Preg_replace keeping wildcards?
Posted: Mon Mar 14, 2011 8:27 am
Hello,
I am trying to parse $lan_content (which contains HTML) for hyperlinks and tack on the string 'lan='.$language at the end of the hyperlink URL. I am not sure how to go about replacing the wildcards properly. At the same time I would like to know if my regex patern makes sense (assuming it will do this for all index.php pages. There's alot going on here and I am not very experienced with regex.
I expext a hyperlink to be declared either:
href="index.php?_variables_"
href="/index.php?_variables_"
href='index.php?_variables_'
href='/index.php?_variables_'
I am trying to parse $lan_content (which contains HTML) for hyperlinks and tack on the string 'lan='.$language at the end of the hyperlink URL. I am not sure how to go about replacing the wildcards properly. At the same time I would like to know if my regex patern makes sense (assuming it will do this for all index.php pages. There's alot going on here and I am not very experienced with regex.
I expext a hyperlink to be declared either:
href="index.php?_variables_"
href="/index.php?_variables_"
href='index.php?_variables_'
href='/index.php?_variables_'
Code: Select all
preg_replace('#href=".?index.php?.*"#', '#href=".?index.php?.*lan='.$language.'"#', $lan_content);