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