SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to work out a regular expression here with prof php programming and am lost.

    Basically, i want to get a bit of a string by setting the start point and the end point.

    Say it was

    $string ="There was a house on a hill"

    i want to set $var1 = There and $var2= hill

    and then somehow get " was a house on a " out of $string and call this something else?

    any ideas?

    for what i am really trying to do is convert

    From: Harjaskara Rai <name@domain.com>

    to name@domain.com

    starting at < and ending at >

    help really apprecaited.

  2. #2
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The following snippet should do the trick:
    PHP Code:
    <?
    $foo 
    'From: Harjaskara Rai <name@domain.com>';
    eregi("<([^>]*)>$",$foo,$email);
    echo 
    $email[1]; //output: name@domain.com 
    ?>
    Hope that helps.

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks! that looks great... one thing:

    i am running through an array so how would i turn it into an if clause. I am doing the following for the subject:

    PHP Code:
    if (eregi("Subject:"$data[$count], $arr)) {
    $subject substr($data[$count],9);
    } else {
    echo 
    "failed to find return email<br>";


  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    will

    PHP Code:
    if (eregi("<([^>]*)>$",$foo,$email)); 
    just return true if it finds it and false if it does not in the same way as the one above?

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I believe so - if the regular expression matches the string, it should evaluate to true.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, that bit worked.

    I have a problem though. Although the regex matches what i asked for, it turns out that when going through the email array line by line it does not work.

    I think that is because the line ends in a "new line" tag like \r\n and for some reason this makes the reg-ex fail.

    What do i need to do to alter it so that what comes after the > does not matter?

    Thanks again, so close...

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i got it, just needed to take of the end $.

    Thanks a lot RobP for that, has helped a lot and i think i understand regular expressions a lot better now!

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you wanted to include any other possible characters, but want that whitespace removed, you can try something like this:

    Code:
    $var = trim($var);
    That will remove all general whitespace characters from the front and back of the string, but not in the middle. Good luck!

  9. #9
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wicked thanks, i see how i could do it that way.. i want karma back so i can give it to you two

  10. #10
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, we'll all have to settle for SitePoints for now, which actually look pretty cool! Wayne has called them the "currency" of the SitePoint Forums - sounds cool to me.

  11. #11
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but how do you give them?

  12. #12
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This shall explain all, my friend:
    http://sitepointforums.com/showthrea...threadid=16333

    I think they look great - I don't totally understand them yet, but we'll probably have to see them to understand them.


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
  •