lpa;10947106 wrote:I want to remove anything, just leaving link which is located <a href="here">. If I wanted to keep the link which is located between >here</a> I could use strip_tags function. The link between < and </a> is shortened to prevent design distortion with long links.
Ok got what you want. You can replace the $pattern to below.
Previous version mistook \w with \s. Correct is \s.
$pattern='#<\sa.+?href\s=\s"(.?)".?>.?<\s/\sa\s*>#i';
Above enforce the check to really make sure <a..> ... </a>, that is a tag has an ending tag before extract the href information.
$pattern='#<\sa.+?href\s=\s"(.?)".*?>#i'
Above will run faster but it does not really check <a> has an ending tag and just extract the href information.
Please also note since I uses preg_match, the second element is what you want instead of the first element.
Extract from PHP.net
If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
Thanks.