Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    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.



    .
    Last edited by jeddi; 01-19-2013 at 07:46 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    Try
    PHP Code:
    $output preg_replace'/[^0-9]/'''$string ); 
    If you can't stand behind your troops, feel free to stand in front of them
    Semper Fidelis


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •