Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php regex

Options
  • 02-05-2008 4:01pm
    #1
    Registered Users Posts: 26,581 ✭✭✭✭


    hey guys,feel like i'm relying on you guys way too much.

    i'm coming from a perl/cgi background and moving to PHP for some projects,

    as you know regular expressions are used widely in perl/cgi and i became a somewhat expert at them but trying to replicate the same standards in php is proving quite taxing.

    i have an entry in a column in a database that's delimited by a tilde (~) an example line would be like so:

    yes~no~maybe~go~away~joe

    what i want to do is to split this so that i can store each value into a variable for further processing.
    in perl this was easy, all it was was to do this:

    if($str =~ /~(.+)~(.+)~(.+)~(.+)~(.+)~(.+)/ )
    {
    var1= $1;
    var2= $2;
    ...
    var6= $6;
    }

    as far as i was aware this was called grouping in perl but when i tried googling for the same functionality i can't find nothing, just regular match a simple pattern.

    anyone have any good web resources they'd like to share?


Comments

  • Registered Users Posts: 3,401 ✭✭✭randombar


    explode would be the best one for this i reckon


  • Registered Users Posts: 26,581 ✭✭✭✭Creamy Goodness


    ahhh you genius.

    i knew php.net had a similar documentation ala javadocs but it's impossible to search for functions when you don't know the names.

    thanks man.


  • Registered Users Posts: 3,401 ✭✭✭randombar


    Ya de lads on here are brilliant for giving the names of functions!

    god bless boards!


  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    Cremo wrote: »
    i'm coming from a perl/cgi background and moving to PHP for some projects,
    As you know perl regex, you can use the Perl Compatible Regular Expression functions.
    Cremo wrote:
    i knew php.net had a similar documentation ala javadocs but it's impossible to search for functions when you don't know the names.
    Then I suggest looking at the category index.


Advertisement