Reputation: 27
I have a variabe named $link in PHP that repeats itself and it has data like:
http://www.ankinfos.com/our-portfolio/www.abc.com
http://www.ankinfos.com/our-portfolio/www.cab.com
http://www.ankinfos.com/our-portfolio/www.zzz.com
.
.
.
.
http://www.ankinfos.com/our-portfolio/www.lal.com
I want to remove the text or data before www.abc.com so that it becomes
http://www.ankinfos.com/our-portfolio/www.abc.com
to
www.abc.com
and http://www.ankinfos.com/our-portfolio/www.abc.com
to
www.cab.com
and so on
Please let me know any solution for that in jquery or php
Upvotes: 0
Views: 149
Reputation: 14025
Use split()
function in javascript
var fullLink = "http://www.ankinfos.com/our-portfolio/www.abc.com";
var url = fullLink.split('/');
url = url[url.length-1]
alert(url)
And explode()
in PHP
Upvotes: 0
Reputation: 2768
http://php.net/manual/en/function.explode.php
$myArray = explode("http://www.ankinfos.com/our-portfolio/", $link);
array_shift($myArray);
print_r($myArray);
This will explode each url (Which I assume is constant) and will remove it's first element (since the delimiter is at the start, it will cause an empty string to be placed as the first item).
Now, you can iterate the items.
Upvotes: 0
Reputation: 475
I think the easiest way in php is to do
$url = "http://.../www.abc.com";
$url = explode('/', $url);
$yourUrl = $url[count($url) - 1];
As for javascript:
var url = "http://.../www.abc.com";
url = url.split("/");
var yourUrl = url[url.length - 1];
Upvotes: 2