Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Small trouble with regular expressions

    Hey guys!
    Please will somebody help me with this?
    Link now looks like this:

    <a href="this-is-some-folder/word1-word2-word3.html" target="_blank">this is some folder/word1 word2 word3</a>

    and I need to be without ’this is some folder/’ (highlighted with red) like this

    <a href="this-is-some-folder/word1-word2-word3.html" target="_blank">word1 word2 word3</a>

    This is my PHP code:

    <?php
    function makeLinksFromWords($text)
    {
    $text = html_entity_decode($text);
    $text = " ".$text;

    $text = preg_replace('/ link_in_folder:(\S+)/e', '" <a href=\""."\\1.html\""." target=\"_blank\">".str_replace("-"," ","\\1")."</a>"', $text);
    $text = preg_replace('/(<a.+>)(\.+)(<\/a>)/Ue',"'$1'.preg_replace('{.+/}','','$2').'$3'",$text);
    return $text;
    }

    // Live Example
    echo makeLinksFromWords("This is a example for link in folder: link_in_folder:this-is-some-folder/word1-word2-word3");
    ?>

    I would appreciate little help with this one.
    Thank you advance
    Cheers!

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    PHP Code:
    $output preg_replace('%(<a\b[^>]+>)(.*?/)([^/<]+</a>)%''$1$3'$input); 
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    young_coder (02-25-2010)

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    14
    Thanked 0 Times in 0 Posts
    What’s the beautiful piece of code...
    Thank you very much...


  •  

    Posting Permissions

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