Web Analytics Made Easy -
StatCounter preg_replace() - CodingForum

Announcement

Collapse
No announcement yet.

preg_replace()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    Why do you want to do it in one line?
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting

    Comment


    • #3
      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)

      Comment


      • #4
        Good question but why do you want to do that!
        Last edited by root; Jun 25, 2002, 06:18 AM.

        Comment


        • #5
          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; Jul 1, 2002, 07:43 PM.

          Comment


          • #6
            Thank you!

            Comment

            Working...
            X