I'm missing somethings that make me fail on using recursive (?R).
An example to explain my problem 'clearly':
$str1 = "somes text -start bla bla FIND bla bla bla FIND bla FIND bla end-";
$str2 = "somes text -start bla bla FIND bla bla bla FIND bla FIND bla end-";
$my_pattern = "-start .*(FIND).* end-";
preg_replace_callback($my_pattern, 'callback', $str1.$str2);
It will only match the very last FIND.
With the 'ungreedy' option i'll match the 1st FIND of both $str.
But how can i get all of them ? I tried to used '(?R)' but i dont really understand how it work.
Thank.
EDIT: The real work is to find all the 'title' property betweem <a>
& </a>
.
I know it's not optimise to use regex to parse html but it's just a work from school to learn regex.
That's why i didnt put the real work, i wanted to understand and be able to do it myself.
<html>
<head><title>Nice page</title></head>
<body>
Hello World
<a href=http://cyan.com title="a link">
this is a link
</a>
<br />
<a href=http://www.riven.com> Here too <img src=wrong.image title="and again">
<span>Even that<div title="same">all the same</div></span>
</a>
</body>
</html>
My job is too put every titles in uppercase (title="A LINK" for example) using regex.
My last pattern was:
#<a .* title=\"(.*)\".*</a>#Uis
Made me catch (title="a link") and (title="and again"). Your method should work (stribizhev) but i didnt succeed to implement it, i'm still on it.