Hi,
Here's a simple question
How can I do the following:
$string = "href="../../../test1/testing/test.html"; or $string = "href="../../testing/test.html";
change string to get rid of the beginning so that
$string = 'href='http://www.mysite.com/testing/test.html"';
$string could have multiple href.
Thank you
$string = preg_replace('/(\.\.\/)+/', 'http://'.$_SERVER['HTTP_HOST'].'/', $string);
something along those lines.
Hi Drew,
Thanks for the code.
but how do I get rid of the test1 in $string = "href="../../../test1/testing/test.html";
I get: href="http://www.mysite.com/test1/testing/test.html"
it should be :
href="http://www.mysite.com/testing/test.html"
I guess I am asking for a way to search for href=" and /testing and replace it with href="http://www.mysite.com/testing
Thanks for your help
Sorry to ask such simple questions.. I just do not understand these REGEX stuff!
a literal str_replace would work, you could do an if substr ../../../test1/ is in the link replace ../../../test1/ with http://www.mysite.com/ and if substr ../../testing is in the link replace it with http://www.mysite.com/testing
it's really easy and the php dot net website will tell you enough about substr and str_replace so that you can write this script. you may want it to open all of the files within the directory and then open them and replace the selected text
The problem is that there are multiple href in the string and it can be any number of characters between href and testing.
like:
href="XXXXXXXXXXXX/testing/test.html"
so it would have to be a preg_replace or ereg_replace.