It is necessary to skip the text through the function / regulars, that would be replaced smiles. Text template in the form :smile_(номер):

Entry: Текст :smile_5: текст текст :smile_1: текст

Output: Текст <img src="/5.png"> текст текст <img src="/1.png"> текст

How to do, hint, I'm in regulars 0.

  • to my decision. if you add $ text to the database, you must use htmlspecialchars ($ text) and mysqli_real_escape_string ($ text); - ikerya

2 answers 2

You can like this:

 <?php $text = 'Текст :smile_5: текст текст :smile_1: текст'; $text = preg_replace('/:smile_(.*?):/', '<img src="/$1.png">', $text); echo $text; ?> 

PS If you add $text to the database, then be sure to use htmlspecialchars($text) and mysqli_real_escape_string($text)

  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin

don't need regulars here use string_replace

 $arrayText = array( ':smile1:', ':smile2:' ); $arrayPic = array( '<img src="/test/smile1.gif"/>', '<img src="/test/smile2.gif"/>' ); $message = str_replace($arrayText,$arrayPic,$message); 
  • List all emoticons? Not that arrays will not work. - Rammsteinik
  • @Rammsteinik To hammer the brain to the server regularly and leave a hundred vulnerabilities like :smile_<script>alert('xss')</script> or :smile_<?php echo 'test'; ?> :smile_<?php echo 'test'; ?> most the - Naumov