Jump to content

[SOLVED] preg_replace /images


SchweppesAle

Recommended Posts

hi, I'm trying to correct the following code so that it replaces image strings which match the following /images/ or images/ with $domain.'/images'.

 

I tried two different methods:

$introtext = $row['introtext'];

			$pattern = '/images/';
			$replacement = $domain.'/images';
			$introtext = preg_replace($pattern, $replacement, $introtext);

 

this works, however it will also apply to anything which has the word "image" in its name.  I also tried the following.

 

if(preg_match_all('#src=[\'"][^\'"]+[\'"]#i', $introtext, $matches))
				{
					foreach($matches[0] as $val)
					{
					$introtext = str_replace($val, str_replace('/images/',$domain.'/images',$val), $introtext);
					}
				}

 

Doing something like this would probably be more appropriate.  It didn't seem to have any effect on the string though. 

 

image urls use the following format src="images/stories/storyimages/softwarereview-150.jpg".  The first method will actually replace the image in storyimage which confuses me since I included \ on both sides of the word image in $pattern.  I tried using the pattern 'src="images/' but didn't have much luck.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.