oo yeh sorry thats me playing around with the page trying to get preg_replace to work , so at the moment im tryin to find a link with http://s so matches any link that starts with http://safetynet and then i want to replace it so adds in a sub domain. such as shop. so end product looks like http://shop.safetynet. heres a lil script ive tried so far i got the preg match working now im tryin to get the replace bit towork within the statement. <?php $pattern = '(http://s)'; $replacement = '(http://shop.s)'; $file = file_get_contents('http://shop.safetynetdirect.com/cgi-bin/mk_cat.pl?cat=SSHPDG'); if (preg_match ($pattern, $file, $matches)) { echo preg_replace($pattern, $replacement, $file); } else { echo $file; } ?>
Try this: $file = file_get_contents('http://shop.safetynetdirect.com/cgi-bin/mk_cat.pl?cat=SSHPDG'); preg_replace('/<img src="\/.*?>/si', '<img src="http://originalurl.bla/', $file); echo $file; PHP: replace originalurl.bla with the domain hosting the images
all i need to do is add in the subdomain shop onto all of the links to get them to work. so http://shop.safetynetdirect.com instead of what it is atm http:/safetynetdirect.com
ive added this just to match <?php $pattern = '(http://s)'; $file = file_get_contents('http://shop.safetynetdirect.com/cgi-bin/mk_cat.pl?cat=SSHPDG'); if (preg_match_all("(http://s)", $file, $matches)) { print_r($matches); } else { echo $file; } ?> but for some reason when i echo the matches value isnt echoing all of the links, when i know there is alot more links on the website then its matching to.
if you do: preg_match_all('/<a href="\/.*?>si/',$file,$matches); print_r($matches); You will see the other links.. It's because links aren't pointing to http:/s... but /cgi-bin/...
multiple preg_replace in one statement, i got this to work. <?php $pattern = '(/cgi-bin/)'; $replacement = '(http://shop.s)'; $file = file_get_contents('http://shop.safetynetdirect.com/cgi-bin/mk_cat.pl?cat=SSHPDG'); if (preg_match_all("(mk_cat.pl?)", $file, $matches)) { echo preg_replace("(mk_cat.pl?)", "http://shop.safetynetdirect.com/cgi-bin/mk_cat.pl", $file); } else { echo $file; } ?> however if i add in another preg_replace underneath like this then the information from file get contents gets echod onto the page twice. any suggestions <?php $pattern = '(/cgi-bin/)'; $replacement = '(http://shop.s)'; $file = file_get_contents('http://shop.safetynetdirect.com/cgi-bin/mk_cat.pl?cat=SSHPDG'); if (preg_match_all("(mk_cat.pl?)", $file, $matches)) { echo preg_replace("(mk_cat.pl?)", "http://shop.safetynetdirect.com/cgi-bin/mk_cat.pl", $file); echo preg_replace("(/cgi-bin/)", "http://shop.safetynetdirect.com/cgi-bin/", $file); } else { echo $file; }