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 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Small trouble with preg_replace

    Hey guys!
    I'm working on this little script but I’m novice with PHP and I can not find out solution for this alone, so please will somebody help me.
    Link looks like this:
    <a href="word1-word2-word3">word1-word2-word3</a>
    And I need to be without hyphens like this in part highlighted with red
    <a href="word1-word2-word3">word1 word2 word3</a>

    Here is my script
    PHP Code:
    <? 
    function makeLinksFromWords($text)
    {
    $text html_entity_decode($text);
    $text " ".$text;

    $text preg_replace('/ link:(\S+)/'' <a href="$1">$1</a>'$text); 
    return 
    $text;
    }

    // Live Example
    echo makeLinksFromWords("This is a example for link link:word1-word2-word3");
    ?>
    Would appreciate some help with this one and thank you advance
    Cheers!
    Last edited by Inigoesdr; 02-21-2010 at 06:29 PM.

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    90
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Thumbs up

    Try something like this:

    PHP Code:
    $text preg_replace('/ link:(\S+)/e''" <a href="."\\1".">".str_replace("-"," ","\\1")."</a>"'$text); 
    Regards

  • Users who have thanked koko5 for this post:

    young_coder (02-21-2010)

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Man, you are genius and if I could buy you a bear I would.
    Thank you very much.

  • #4
    New Coder
    Join Date
    Mar 2009
    Posts
    90
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Smile

    Glad it helped

    Cheers


  •  

    Posting Permissions

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