Jump to content

substr_replace


kaliok

Recommended Posts

I am trying to come up with a solution that would work like substr_replace but only replace certain characters in the string. Having trouble getting my head around it though:

 

Say, I have a string (including the quotes):

 

"brown fox" +jumped over the +"lazy dog"

 

and I want to replace the spaces between the words with underscores ONLY if they are between the quotes. I have already got the positions of all the quotes into an array and I can therefore work out the number of characters but what I am stumped on is how to use substr_replace or str_replace to do this. Was looking for help creating a function that could do this.

 

The string doesn't always follow the same format, the quotes could appear anyway in the text.

 

The above example should end of looking like this:

 

"brown_fox" +jumped over the +"lazy_dog"

 

Perhaps what I want to do can not be done with these two functions, in which case perhaps someone could suggest an alternative.

 

Any help is greatly appreciated...

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/136096-substr_replace/
Share on other sites

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.