SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ereg Help Needed

    I have a database column with row strings like :

    Code MySQL:
    [code]http://us.st12.yimg.com/us.st.yimg.com/I/yhst-44726496652436_2044_118738##http://us.st12.yimg.com/us.st.yimg.com/I/yhst-44726496652436_2043_28814873##http://us.bc.yahoo.com/b?P=6UtUXNG_QkRW4fT1Twuc.QEYR2q1C0mvJvMADR2a&T=1406gupem%2fX%3d1236215539%2fE%3d23[/code]

    I want to keep everything beforre the first ## and remove everything after it.

    is ereg_replace the correct function? How do i use it?

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Here you go, a quick one-liner.

    PHP Code:
    <?php
    $sString 
    current(explode('##''http://us.st12.yimg.com/us.st.yimg.com/I/yhst-44726496652436_2044_118738##http://us.st12.yimg.com/us.st.yimg.com/I/yhst-44726496652436_2043_28814873##http://us.bc.yahoo.com/b?P=6UtUXNG_QkRW4fT1Twuc.QEYR2q1C0mvJvMADR2a&T=1406gupem%2fX%3d1236215539%2fE%3d23'));
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me see if I understand this. Using explode, you are splitting the string by ## and putting the results in an array.

    Using current, grabs the first value in the array, which is what I want.

    That's a pretty ingenious way to do it! thanks!
    Last edited by bruin03; Mar 26, 2009 at 15:57. Reason: mispelling

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Spot on! All you needed was a little nudge.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm soo used to the way JS handles array, using array_pop and array_shift just comes soo much more naturally to me than current(), I like how that works though.


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
  •