Jump to content

Replace Disp "Text" with "Text"_ using preg_replace


qureshi

Recommended Posts

Hi there,

 

I have been trying to solve this myself, but have had no luck.

 

I have this:

Disp "Weight:"
Disp X/Y

 

But I want to transform it to:

 

"Weight:"_
X/Y_

 

Using this:

preg_replace("/Disp(.*?)/i","$1_",$string)

 

But it doesn't work. Instead I get:

 

_ "Weight:"
_ X/Y

 

I'm running php 5.3 on windows. Latest XAMPP.

 

Thanks in advance,

 

Nadeem

Be aware that given the example string, there will be Carriage Return (\r or ASCII 13) characters left floating around since the Windows-style line ending (\r\n) is used.

 

Oh.. :)

echo str_replace(array("\n", "\r"), "", preg_replace("/Disp(.*)/i","$1_",$string));

 

Should sort it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.