2

I have this sitation:

..<img src="//http://www... OR ..<img src="/http://www... OR ..<img src="////http://www...

(/ - may be much)

How delete / before http? Resultat always should be:

..<img src="http://www...

Thanks ;)

1
  • Can you show a real life example? Commented Sep 30, 2010 at 11:15

4 Answers 4

3

This should do the trick.

ltrim($url, "/");

This seems like a rather ad hoc solution. You might want to get to the bottom of the issue and eliminate it at source.

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

Comments

0

A regular expression along the lines of this should do the trick I think:

$string = preg_replace('/="\/+http:/', '="http:', $string);

1 Comment

Yes it does. Could you post proper example of what you're after?
0

Assuming that the url is defined in a variable within your PHP, ltrim() could be the answer

$url = ltrim($url,'/');

though you wouldn't be able to use this option if you had local url's (eg '/images/img.gif') without the 'http://'

Comments

0

You could do something like this (str_replace() because it is faster than a regular expression):

$markup = str_replace('//http://', 'http://', $markup);

Why do you need this? It might be better to eliminate the source of this problem.

Comments

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.