Hi, I have the following function which changes a URL in my string. Its working fine but i want to stop it changing the image name also. E.g. Here is an example string. <h1>Welcome to website</h1> <p><strong><u>My title</u></strong><img src="http://ablered.mysite.info/uploads/images/thumbs/ablered.mysite.info_--_532966935.PNG" width="250" align="right" style="margin: 0px 0px 0px 25px;"></p> Code (markup): As you can see the image contains the same domain in the image name. I only want the domain changing in the link but not the image. My function changes them both but i cant see how to do just the URL. This is the function. function formatUrlsInText($text, $newURL) { return preg_replace( '/[a-z0-9]+\.mysite\.info/i' , $newURL, $text); } Code (markup):
Can't you just make it match the url after http://? Code (markup): so change the function to something like this: function formatUrlsInText($text, $newURL) { return preg_replace( '/http:\/\/[a-z0-9]+\.mysite\.info/i' , $newURL, $text); } PHP: Point: this means you'll need to have http:// Code (markup): in front of replacement url
Thanks - as always, I always recommend chosing "Best solution" within the thread (my post, basically) to help others quickly get to the answer, and also to gain me a "best answer"