php - Remove last \" from link with preg_match_all -
next link example returns 2 links both end \". there no links end \" in example text. when run below preg_match_all() function in wordpress site.
i need fix , links not end \"
here text example retrieve links from:
$banner_link = '<a href="https://mobico.nl/telefoon/?tt=26156_1144596_250041_&r=" target="_blank" rel="nofollow"><img src="http://ti.tradetracker.net/?c=26156&m=1144596&a=250041&r=&t=html" width="300" height="250" border="0" alt="" /></a>'; preg_match_all('!https?://\s+!', $banner_link, $matches); $all_urls = $matches[0]; print_r($all_urls[0]); echo '<br>'; print_r($all_urls[1]);
here result both end \"
https://mobico.nl/telefoon/?tt=26156_1144596_250041_&r=\"
http://ti.tradetracker.net/?c=26156&m=1144596&a=250041&r=&t=html\"
i can str_replace() possible preg_match_all() function.
first of all, there no \"
after r=
in input string, there no way preg_match_all()
returns urls end \"
.
the urls identified preg_match_all()
end "
because regex
permissive.
try one:
$banner_link = '<a href="https://mobico.nl/telefoon/?tt=26156_1144596_250041_&r=" target="_blank" rel="nofollow"><img src="http://ti.tradetracker.net/?c=26156&m=1144596&a=250041&r=&t=html" width="300" height="250" border="0" alt="" /></a>'; preg_match_all('!https?://[^"]*!', $banner_link, $matches); print_r($matches);
the output is:
array ( [0] => array ( [0] => https://mobico.nl/telefoon/?tt=26156_1144596_250041_&r= [1] => http://ti.tradetracker.net/?c=26156&m=1144596&a=250041&r=&t=html ) )
wiki
Comments
Post a Comment