Re: Converting HTML to BBCode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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(
> ' & '	=> ' &amp; ',
> '"&"'	=> '"&amp;"',
> 'W&OD'	=> 'W&amp;OD',
> '&O'	=> '&amp;O',
> 'M&F'	=> 'M&amp;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);
> 
> 
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux