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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.