CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Extracting a number from a string ?? (http://www.codingforums.com/showthread.php?t=286081)

jeddi 01-19-2013 06:35 PM

Extracting a number from a string ??
 
Hi,

I have a string like this:

"villarentfethiye.example.com/18-vacationvillatrekkingturkey"

The bold element "example.com/" will stay constant and so will the "-" (dash or hyphen )
immediately after the number. The other stuff can change a lot.


I need to extract the number. In this case it is 18

What would you say is the most efficient way to extract this using php ?
I will use the number to find the record by it's id number in the db table.

Many thanks.



.

jimhill 01-19-2013 07:28 PM

Try
PHP Code:

$output preg_replace'/[^0-9]/'''$string ); 



All times are GMT +1. The time now is 11:17 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.