I'm kind of new at php and need to parse a url: http://www.someurl.com/directory/214 and use the last digists as a ID. Finally inserting that ID into a mysql db.
Any help would be greatly appreciated..
Thanks..
Tee214..:bemused:
I'm kind of new at php and need to parse a url: http://www.someurl.com/directory/214 and use the last digists as a ID. Finally inserting that ID into a mysql db.
Any help would be greatly appreciated..
Thanks..
Tee214..:bemused:
I think you should look into parse_url(), substr(), and strrchr() :evilgrin:
hello,
i think you should look into this guide too:
http://www.workingwith.me.uk/articles/scripting/mod_rewrite
jjozsi.
djjjozsi's suggestion is best; using mod_rewrite, you could tell Apache (are you using Apache, by the way?) to rewrite http://mysite.com/directory/144 into http://mysite.com/directory.php?id=144 -- example:
RewriteRule ^directory/(\d+)/?$ directory.php?id=$1
The mod_rewrite suggestions assume that the URL in question is the URL of the script being executed. If that is not the case, but you are instead just parsing a URL from some other source, then [man]basename/man might be the simplest solution.
<?php
$url = 'http://www.someurl.com/directory/214';
$id = basename($url);
echo $id;
Thank your help..
Don't forget to mark this thread resolved (if it is).