|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
If the digits are always on the end, you could do something like this:
PHP Code:
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.) |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Help with ereg function. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|