Jump to content


New line confuses preg replace


2 replies to this topic

#1 influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 29 January 2007 - 03:28 PM

so this code:

Quote

<?php
$text = '//Admin settings $hi = "hi"; //Sql settings';
$bbcode = '/(\/\/Admin settings)(.*)(\/\/Sql settings)/';
$html = 'omg';
$output = preg_replace($bbcode, $html, $text);
echo "$output ";
?>
works a treat, it outputs omg,
however

Quote

<?php
$text = '
//Admin settings
$hi = "hi";
//Sql settings';
$bbcode = '/(\/\/Admin settings)(.*)(\/\/Sql settings)/';
$html = 'omg';
$output = preg_replace($bbcode, $html, $text);
echo "$output ";
?>
simply outputs //Admin settings $hi = "hi"; //Sql settings

any ideas?:s
thank you p2l!
henry.

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 29 January 2007 - 03:34 PM

<?php
$text = '
//Admin settings
$hi = "hi";
//Sql settings';
$bbcode = '/(\/\/Admin settings)(.*)(\/\/Sql settings)/s';
$html = 'omg';
$output = preg_replace($bbcode, $html, $text);
echo "$output ";
?>

I have added in the s after the / on the BBCode. The s simply makes the preg_match ignore /n /r /t and a few other tags I think.

Matt

#3 influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 29 January 2007 - 03:39 PM

thanks man:D i couldn't find that anywhere:S
thanks again.
Henry.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users