Page 1 of 1
cut a string php
Posted: Mon Aug 27, 2012 8:59 am
by mekha
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?
Re: cut a string php
Posted: Mon Aug 27, 2012 12:45 pm
by requinix
parse_url would be a great place to start.
Re: cut a string php
Posted: Wed Aug 29, 2012 7:51 am
by mekha
hi man, how can i looping $mysqli insert query with for() loop?
Re: cut a string php
Posted: Wed Aug 29, 2012 2:37 pm
by requinix
I don't think parse_url() can help with that.
General Posting Guidelines. The bit about writing a question carefully is important.
Re: cut a string php
Posted: Wed Aug 29, 2012 3:29 pm
by Live24x7
something like:
will explode the $url into an array $urlparts where each array element will be formed by the occurrence of '/':
Code: Select all
$urlparts[0]=> http:/
$urlparts[1]=> ""
$urlparts[2]=> xxxxxxxxxxxxxxxxxx.com
$urlparts[3]=>mikhastar
$urlparts[4]=>pages
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.