0

Echo $var gives me something like http://342.234.243.142/data/somethingmore/

IP-address everytime is different. Instead of "somethingmore" can something like "/folder/images/2011/gallery/file.jpg" (anything)

How do I strip from this string part with the ip and /data/ folder?

$var could become /somethingmore/

3 Answers 3

2
$url = 'http://342.234.243.142/data/somethingmore/';
echo basename($url);
2
$str = "http://342.234.243.142/data/somethingmore/";
$str = explode('/', $str);

print_r($str);
1
  • @Messi: You should make it more clear what part of URL do you needs? your edit is confusing me. Jul 12, 2011 at 10:46
1

Use this regular expression:

/.*?\/data/

This way you can get a full string after '/data' even if it contains more '/' (slashes). For example, http://342.234.243.142/data/somethingmore/andmore/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.