Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

php regex

  • 02-05-2008 04:01PM
    #1
    Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭


    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, Registered Users 2 Posts: 3,485 ✭✭✭randombar


    explode would be the best one for this i reckon


  • Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭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, Registered Users 2 Posts: 3,485 ✭✭✭randombar


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

    god bless boards!


  • Registered Users, Registered Users 2 Posts: 6,677 ✭✭✭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