General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 17th, 2003, 10:25 AM
stfu stfu is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 19 stfu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help with ereg function.

Hi guys,

I have a few hundred links in mysql db from this kind:

Code:

http://us.imdb.com/Title?0122690





or

Code:

http://www.imdb.com/title/tt0338280/





and i wonder how i can get only this symbols: 0338280
example if i have this url:

Code:

http://www.imdb.com/title/tt0338280/





i want to get only symbols that are after 'title/tt'
and if i have another url from first kind example:

Code:

http://us.imdb.com/Title?0122690





i want to get symbols that are after 'Title?'

I think that can be done by eregi function but i'm not very familiar with it.

So can someone help me or give me any idea?

Thanks in advance.

Reply With Quote
  #2  
Old October 17th, 2003, 10:50 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
If the digits are always on the end, you could do something like this:

PHP Code:
 $url=preg_replace("/?/","/",$url); //May need to escape the ?
$parts=split("/",$url);
$id=preg_replace("/tt/","",$parts[sizeof($parts)-1]); 


First you're replacing the question mark with a slash. Then, now that you've got a common delimiter among the two types of string, you split the string on that delimiter and stick the parts into an array. Then you assign the last element of the array to $id, stripping out "tt" on the way in. This is a pretty specialized piece of code, and you'd want to come up with something more elegant for more general use, but if this is all you need and it's safe to assume that digits are at the end of the string in all cases, this code ought to work. One extra step you may want to throw in there is checking the last element of the array to see if it's blank, and if it is, to pop it off the array. (If there's a concluding slash on the path, the last element will be blank.)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Help with ereg function.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT