0

I have a text box with its value as <img src="http://localhost/wp/review/wp-content/uploads/2010/11/Sunset.jpg" />

I have to replace this text box value to 'http://localhost/wp/review/wp-content/uploads/2010/11/Sunset.jpg' That is the main target is to remove img tag and keep only the src value.

Thanks Ashok Negi

ashok
  • 1

3 Answers3

0

hi you can use this method instead

$str = '<img border="0" src=\'/images/image.jpg\' alt="Image" width="100" height="100"/>';

preg_match('/(src=["\'](.*?)["\'])/', $str, $match);  //find src="X" or src='X'
$split = preg_split('/["\']/', $match[0]); // split by quotes

$src = $split[1]; // X between quotes

echo $src;
Eugene Tang
  • 83
  • 2
  • 8
0

Strip 10 characters from the beginning and 4 characters from the end. Or use a HTML parser.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

You could also look into creating a regex to do this. Simplest method.

Jonas
  • 1