I have a string:
$string = '<a href="/news/blablalba">some text</a>';
I need to add target="_blank" attribute inside tag above and http://mysite.kz before /news/blablabla.
preg_replace("/<a href=\"\/(.*)\">(.*)<\/a>/iU", "<a target=\"_blank\" href=\"\/(.*)\">(.*)\">(.*)<\/a>", $string);
code above won’t works. Help please!
UPDATED
Solved this task:
$match1 = preg_replace("/<a href=\"\/(.*)\">(.*)<\/a>/i", "<a target=\"_blank\" href=\"http://nashmir.kz/$1\">$2</a>", $string);
preg_replace('/^<a\s+(href=")(\/news\/)/i', '<a target="_blank" $1http://mysite.kz$2')Rule of thumb: you only need to match what is necessary. Except in very rare cases, you never need to match the whole input.