SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Learning more about preg_*, eregi_*, and mysql Joins

    Hi

    Can someone recommend some online resources to learn the above mentioned php functions? I read the php manual about the two and found it too advanced for me, with all the slashes and wildcards. Is there any tutorial which breaks down everything step by step? Thanks!
    Last edited by The Red Guy; Sep 10, 2003 at 22:11.

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the resource, that was very kind of you! However all the article did was to introduce preg_match, are there some which teaches *_replace? I know I can use the concepts, but I'm still unclear about things such as []. Are they seperators like ()?

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you should know (and where you should begin your searching) is tha preg_* functions use Perl Compatible Regular Expressions (aka PCRE) and the ereg_* functions use POSIX functions. Reality is you should really only concern yourself with PCRE's because, aside from Apache 1.3, everything else pretty much uses PCRE. [url=http://regexlib.com/]Here[/url is a resource you should bookmark. It is geared toward DOT-NET, but DOT-NET uses PCRE as well so syntax is identical.

    Now how to use the actual preg_* functions? This is something you will look at php.net for.

    Say you have a preg_match.
    PHP Code:
    preg_match('#\[some text](.+)\[goes here]#i',$text); 
    That will hypothetically match:
    1. Some Text about me goes here.
    2. Some text describing ridiculous matters of life and death goes here
    3. SoMe TeXt make me go blah goes hERE too

    But not just:

    Some text goes here.

    Now say you wanted to search a whole paragraph for a single phrase and echo it into a string. You'd use preg_replace because you are replacing the whole block of text with something else.
    PHP Code:
    $snippet preg_replace('#\[some text](.+)\[goes here]#i',"$1",$paragraph); 
    Now:

    There's plenty of things to consider. Really, the bottom line is that the decision isn't yours to make. You may want some text that you feel goes here to reflect those sentiments.
    Becomes:
    that you feel
    By using $1, in the replace area, I am saying that I want to take the first matched grouping (which was the (.+)).

    It's all very complex and you'll have to read about it, but that's a brief overview...

    Aaron
    Aaron Brazell
    Technosailor



  5. #5
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MySQL uses POSIX too .
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Point well taken.
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright thanks, (I do not wish to start another thread), can someone point me to a resource which teaches on JOINS in mysql? I've learnt the basics, I need something more in dept.

  8. #8
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should start another thread
    Aaron Brazell
    Technosailor




Bookmarks

Posting Permissions

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