hi... for example i have this link:
http://xxxxxxxxxxxxxxxxxx.com/mikhastar/pages/
how can i cut the link above and echo this:
/pages/....
i mean i want to cut and echo every thing after mikhastar ...because mikhastar is a fixed word....but the xxxxxxxxxx.com is not fixed!....
any help please?
cut a string php
Moderator: General Moderators
Re: cut a string php
parse_url would be a great place to start.
Re: cut a string php
hi man, how can i looping $mysqli insert query with for() loop?
Re: cut a string php
I don't think parse_url() can help with that.
General Posting Guidelines. The bit about writing a question carefully is important.
General Posting Guidelines. The bit about writing a question carefully is important.
Re: cut a string php
something like:
will explode the $url into an array $urlparts where each array element will be formed by the occurrence of '/':
you can then echo $urlparts[4]; which will echo the last part of your string.
though there could be more efficient ways of doing this which i may not be aware of.
Code: Select all
$urlparts = explode("/", $url);
Code: Select all
$urlparts[0]=> http:/
$urlparts[1]=> ""
$urlparts[2]=> xxxxxxxxxxxxxxxxxx.com
$urlparts[3]=>mikhastar
$urlparts[4]=>pages
though there could be more efficient ways of doing this which i may not be aware of.