Jump to content

Recommended Posts

No, you could not solve that using just str_replace(). You *may* be able to use preg_replace().

 

But, you need to clarify your requirement. Are yu wanting to replace every fifth LETTER or every fifth CHARACTER? There is a bug difference. The former is definitely more difficult. You can accomplish the latter with

$replaced = preg_replace("#(.{4}).#", '${1}X', $input);

I tried the code you gave me but it replaced EVERY fifth, I just want the fifth only.

 

Yeah, that's right. The code I provided replaces EVERY fifth letter because that is EXACTLY what you requested.

I want to be able to replace, let's say, every fifth letter from a string.

 

I guess I was supposed to assume you wanted something different than what you asked for?

 

If this is not what you want I hope someone else is willing to help you because I won't

$newstring = substr_replace($input, 'X', 4, 0);

I tried the code you gave me but it replaced EVERY fifth, I just want the fifth only.

 

Yeah, that's right. The code I provided replaces EVERY fifth letter because that is EXACTLY what you requested.

I want to be able to replace, let's say, every fifth letter from a string.

 

I guess I was supposed to assume you wanted something different than what you asked for?

 

If this is not what you want I hope someone else is willing to help you because I won't

$newstring = substr_replace($input, 'X', 4, 0);

 

Thanks, I'm sorry for wording the thread wrong.. was that attitude necessary?

We're volunteers, most of us professionals, giving our free time to help beginners 'cause we were all there once.

 

If you want to ask for help, it's a good idea to be accurate in, think about, and proof read your questions/responses.

 

When you don't care enough about your question to ask it properly, we feel you've wasted our time. Even in your reply, you still didn't realize he had given you exactly what you'd asked for.

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.