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 6 of 6

Thread: preg_replace()

  1. #1
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    preg_replace()

    How do i do this in one line.

    preg_replace("[bold]","<b>",$body);
    preg_replace("[/bold]","</b>",$body);

    i want to end up with <b>all the text in between</b>

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why do you want to do it in one line?
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,078
    Thanks
    11
    Thanked 98 Times in 96 Posts
    basically you dont

    never use regex if str_replace will do the same job... str_replace now accepts arrays as arguments...

    run this to discover the truth
    PHP Code:
    <?
    $str
    ="did I not tell you that [BOLD]ASP[/BOLD] rocks the house and all your pages are belong to [BOLD]ASP[/BOLD]";

    $in=array('[BOLD]','[/BOLD]','ASP');
    $out=array('<b>','</b>','PHP');
    $str=str_replace($in,$out,$str);

    echo 
    $str;
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Good question but why do you want to do that!
    Last edited by root; 06-25-2002 at 11:18 AM.

  • #5
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    preg_replace("[bold]","<b>",$body);
    preg_replace("[/bold]","</b>",$body);

    This works


    $body = "[bold]All this text[/bold]";

    Here it is in one line:

    $body = preg_replace("/\[bold\](.+?)\[\/bold\]/i","<b>\\1</b>",$body);
    Last edited by cpatzer; 07-02-2002 at 12:43 AM.

  • #6
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you!


  •  

    Posting Permissions

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