0

would like to replace all occurence of, double quote included

"http://somebunchofchar"

to

"link"

I came up with preg_replace("/\"http:\/\/.\"/i", "\"link\"", $string);

KJW
  • 15,035
  • 47
  • 137
  • 243

4 Answers4

2

Just add an asterisk and question mark after dot

preg_replace("/\"http:\/\/.*?\"/i", "\"link\"", $string);

shift66
  • 11,760
  • 13
  • 50
  • 83
2
$string = preg_replace('#"http://.+"#', '"link"', $string);
IvanGL
  • 751
  • 5
  • 22
1

You can use:

preg_replace('~"http://[^"]*"~i', '"link"', $string);
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Just look here: http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2&AspxAutoDetectCookieSupport=1 how to match an URL with the correct pattern; than use preg_replace with the particular regexp pattern ;-) (you can add those quotes at the start and end to the pattern yourself quite easily) :-)

tim
  • 9,896
  • 20
  • 81
  • 137