Reputation: 528
I have seen lots of similar queries to this, but am struggling to get them to work in my application because I still don't fully understand regular expressions!
I'm using the old FCKEditor WYSIWYG to upload an image, but need to store the src as the full URL rather than the relative path.
At the time I need to do the replace, I've already replaced quotes with " so the pattern I'm looking for needs to be: src=\"/userfiles/
This needs to be replaced with src=\"http://mydomain.com/userfiles/
Thanks for your suggestions!!
Upvotes: 0
Views: 2411
Reputation: 1916
you can actually do this with a str_replace and it'd be simpler but here's a preg.
$html = preg_replace('!src="/userfiles/!', 'src="http://mydomain.com/userfiles", $html)
here's the str_replace
$html = str_replace('src="/userfiles/', 'src="http://mydomain.com/userfiles", $html)
if there are spaces here and there you'll need the preg and you'll want to add \s* in the places that have spaces.
Upvotes: 2