Re: Converting HTML to BBCode
| From: | J_K9 | Date: | Mon, 06 Mar 2006 19:33:32 +0000 |
| Subject: | Re: Converting HTML to BBCode | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-231540@lists.php.net to get a copy of this message | ||
Hi Al,
Thank you for your reply. I have changed my code to the following:
-------CODE-------
<?php
$text = $_REQUEST['text'];
echo '<br /><br />';
$translate_array = array(
'<strong>' => '[b]',
'</strong>' => '[/b]',
'<b>' => '[b]',
'</b>' => '[/b]',
'<em>' => '[i]',
'</em>' => '[/i]',
'<i>' => '[i]',
'</i>' => '[/i]',
'<u>' => '[u]',
'</u>' => '[/u]',
'<a href="' => '[url=',
'</a>' => '[/url]',
'<img src="' => '[img]',
' border="0" />' => '[/img]',
'<ol>' => '',
'</ol>' => '',
'<li>' => '[list]',
'</li>' => '[/list]'
);
$find_array= array_keys($translate_array);
$replace_array= array_values($translate_array);
$text= preg_replace($find_array, $replace_array, $text); // Line 41
echo '<textarea name="output">' . "$text" .
'</textarea>';
?>
-------/CODE-------
However, I get the following error appearing in between the two
textareas:
-------ERROR-------
Warning: preg_replace() [function.preg-replace]: No ending matching
delimiter '>' found in /var/www/htdocs/file.php on line 41
Warning: preg_replace() [function.preg-replace]: No ending matching
delimiter '>' found in /var/www/htdocs/file.php on line 41
Warning: preg_replace() [function.preg-replace]: Delimiter must not be
alphanumeric or backslash in /var/www/htdocs/file.php on line 41
-------/ERROR-------
Thanks for your help so far! It'd be great if this works out ;)
Cheers,
J_K9
> Here is an example for you.
> First make an array like this:
>
> $translate_array= array(
> ' & ' => ' & ',
> '"&"' => '"&"',
> 'W&OD' => 'W&OD',
> '&O' => '&O',
> 'M&F' => 'M&F',
> );
>
> Then use:
>
> $find_array= array_keys($translate_array);
>
> $replace_array= array_values($translate_array);
>
> $text= preg_replace($find_array, $replace_array, $text);
> //with preg_replace you can make the $find stuff case insensitive
>
> OR simply:
>
> $text= strtr($text, $translate_array);
>
>
>
>