SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    eregi_replace help

    Okay using a bit of code from Kevin Yanks PHP article on webmasterbase.

    This code converts some like [L=www.sitepoint.com] Visit sitepoint [EL] to the actual HTML code.

    PHP Code:
    $Story eregi_replace"\[L=([-_./a-zA-Z0-9!&%#?,'=:~]+)]""([-_./a-zA-Z0-9 !&%#?,'=:~]+)\[EL]""<A HREF=\"\\1\">\\2</A>"$Story); 
    My question is how do i convert the html code back into the orignal [L=URL] linktext [EL] form? I tired reversing it a little and got an error can't seem to get it right. Thanks for all your help guys.
    Garlic bread, I've tasted it, it's the future

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this,

    Code:
    ereg_replace("<a html=\"([-_./a-zA-Z0-9!&%#?,'=:~]+)\">([a-zA-Z0-9.]+)</a>","[L=\1]\2[EL]",$story);
    Paul
    Last edited by Paul S; Aug 13, 2001 at 16:43.

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    number one i ALWAYS use preg_replace cuz it's twice as fast. i think i'd do it like this:

    PHP Code:
    $story preg_replace('#<a href="(.*?)".*?>(.*?)</a>#is''[L=$1]$2[EL]'$story); 
    to use the $n in the replacement you need at least PHP 4.0.4. otherwise use the \n thing.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to both of you I guess i should go read up about preg_replace huh?
    Garlic bread, I've tasted it, it's the future

  5. #5
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am looking for the opposite of this

    PHP Code:
    $Story ereg_replace("\n\n","<P>",$Story); 
    Something that would take the <P> tag and insert a double line feed. I though this would be simple just reversing it like this

    PHP Code:
    $Story ereg_replace("<P>","\n\n",$Story); 
    but for some reason that only enters one linefeed and only one extra line is adding therefore the old formatting is not restored. I have been on IRC for about 30 minutes with this problem and every solution people came up with did not work. This included messing with char(10) and char(13) or something like that lol.

    any ideas? I'm counting on you guys.

    Thank you
    Garlic bread, I've tasted it, it's the future

  6. #6
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $s = preg_replace("/<p>/i","\n\n",$s); works for me.
    ck :: bringing chris to the masses.

  7. #7
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've had enough experience with Anarchos to know that he's usually right.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  8. #8
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Aes =).
    ck :: bringing chris to the masses.

  9. #9
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I recently found myself doing a replacement of all <br>'s with \n and got my solution from this forum, so thanks all.

    My question is while this code works for me, I don't understand what the 'i' is doing in it. It seems to be critical that it is there. Can someone tell me what its for?

    $message2 = preg_replace("/<br>/i","\n",$message);

  10. #10
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It makes the regular expression case-insensitive, so it'll parse <br> and <BR>.
    ck :: bringing chris to the masses.

  11. #11
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The "i" makes it case insensitive

    Edit:

    Oh Anarchos!


    sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  12. #12
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you both.


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
  •