I have so开发者_C百科me urls in a database with querystrings that were constructed by php, and some of them contain erroneous strings that are causing me problems. These strings look like html attributes, and I don't think they are added any more but I need to be able to process the urls to remove these parts, and there are too many to do it manually.
The bad parts all look something like: \" ismap=\"ismap\" usemap=\"usemap\"#_mapname2112__\" height\"534\" alt=\"
The number after mapname varies, and the height might do although the examples I've looked at so far all say 534, I can't be sure the error has different values on other installations of the software.
Assuming I have the url in a php string, how can I process this string to remove these bad parts? I'm suspecting this would be a good use case for a regular expression...
If it's only "some urls" as you write, doing it manually is the fastest and effortless option.
Furthermore, you have invalid HTML in your application since that's how you got those problematic URLs in the first place. Fix that.
The following fixed it for me without using regular expressions. Probably only because the bad bits were at the end of the url...
$url_parts = parse_url($url);
$qs = $url_parts['query'];
$qs = str_replace('\" ismap=\"ismap\" usemap=\"','',$qs);
$url = $url_parts['path'].'?'.$qs;
精彩评论