0

I'm having some very odd and serious problems with a string...

For some reason, certain characters in a string are not passing through any functions correctly, and only in one PHP file (it works fine on other pages).

I had something working two days ago, but now there are problems.

For example, I have a string that looks like this:

http://example.com/v/asd238

I'm trying to change it to be something like this:

http://example.com/first/second/v/asd238

So I had this before:

preg_replace('/http\:\/\/example\.com\/([v|u]*)\/([a-z0-9]*)/i', 'http://example.com/first/second/v/$1/$2');

But for some reason the ':' and '.' make function basically do nothing. Even on functions like strpos() or str_replace().

I'm wondering why, if I even escape the two with '\', what is going on? I can't even remotely figure out why I'm having this problem.

1
  • 1
    So str_replace('/v/', '/first/second/v/', $url) wouldn't work? Commented Sep 9, 2012 at 21:11

1 Answer 1

1

I think this is the best way to do it:

str_replace('http://example.com/', 'http://example.com/first/second/', $url);

More on str_replace()

Sign up to request clarification or add additional context in comments.

11 Comments

Well yes, but as I said, for some odd reason, the time that ':' is in the string, the function does nothing. For example, str_replace('http', 'ftp', $url) works, but not str_replace('http:', 'ftp:', $url)
@sackbot14 - Ties has an error in the way that str_replace() is called, but it works: codepad.org/0HnGGY9O (EDIT: Or at least the way that count is given: codepad.org/BVsSzqtn)
@sackbot14 - And here's your other comment-given example: codepad.org/CwdtVLzy
yeah i was reading the docs wrongly... my bad. the count parameter has to be a variable. this is because it is given the value of the number of replacements made.
@sackbot14 - I'm not seeing an entity here for the colon: codepad.org/9nHeyW0L
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.