Jump to content

[SOLVED] Preg_Replace.


phpSensei

Recommended Posts

Can someone help me with this?

 

I know exactly how to write a preg_replace script, but dont know how to do the following...

 

When a user posts a message, he can add the following stuff:

 

<"b"><"/b"> Sorry, I had to put double quotes because this site reads it as a bold.

<center></center>

:P - tongue

;p - Wink

:0 - Suprised

 

How would you make it so the script finds a string wrapped by the bold, and center, and to find the smilies, and replace them with something of my own.

 

 

And please dont give me answers that dont relate to anything.

 

 

Link to comment
https://forums.phpfreaks.com/topic/60874-solved-preg_replace/
Share on other sites

for simple replacements like these, i think you'd be better off using str_replace().  all you need to do is specify a search string, a replacement string, and the subject to search on.  it's well-suited for smilies in particular.

 

the regex side of things need only come in for complicated tag patterns, where you might be missing a closing tag or opening tag and don't want to propagate those open tags past the string you're outputting.  for the most part, this isn't a huge issue if your posters are responsible.

Link to comment
https://forums.phpfreaks.com/topic/60874-solved-preg_replace/#findComment-302880
Share on other sites

<?php

$sql="SELECT * FROM frontpage ORDER BY id DESC LIMIT 3";

 

 

 

$result=mysql_query($sql);

 

while($row = mysql_fetch_array($result)) {

 

$happy = str_replace(":P", "happy", $row['message']);

 

echo '

<table width="80%"  border="0" align="center">

  <tr>

    <td colspan="2"><div align="center" class="style6">

        <h3>' . $malestr . '</h3>

    </div></td>

  </tr>

  <tr align="center" valign="top">

    <td colspan="2"><div align="center" class="style6">       

      <div align="center"><span class="style8">' . $row['message'] . '

          <br>

          <br>

</span>       

        <hr size="2">

        </div>

    </div></td>

  </tr>

  <tr>

    <td width="100%" height="21"><div align="left"><span class="style5"><img src="files/images/admin_avy.png" width="12" height="12"> user: -- </span> <img src="files/images/comment.png"><span class="style5"> Comments ( 0 ) <img src="files/images/written.png" width="12" height="12"> Date Written:<em>' . $row['date'] .'</em></span></div></td>

    <td width="0%" class="style5"><div align="left"></div></td>

  </tr>

</table>';

 

}

 

?>

 

 

I did this, but it doesnt work.

Link to comment
https://forums.phpfreaks.com/topic/60874-solved-preg_replace/#findComment-302892
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.