Hi all,
I want to create my personal blog and to be able to put code in pre tags. I have created some functions for converting content for and from database.
Basicaly the idea is tha same as
this
but this is not working in my pc. The created functions work on localhost(win7) but didn't work in my linux box(debian server)
I use:
Code:
function txt2db($s){
//$s = str_replace("'", "\'", $s ); // i don't need this since mysql auto escape single quotes (can't find and turn it off)
return $s;
}
function db2txt($s){
// $s = str_replace("\'", "'", $s ); // alse not needed
// $s = str_replace("<pre>", "<pre>", $s );
// $s = str_replace("</pre>", "</pre>", $s );
$s = preg_replace_callback(
'#\<pre\>(.+?)\<\/pre\>#s',
create_function(
'$matches',
'return "<pre>".htmlentities($matches[1])."</pre>";'
),
$s
);
$s = nl2br($s);
return $s;
}
I think it is clear from the function names waht they do.
The problem is that when save & lt; on database it appear < on my edit window and when I edit once an article all entities are converted in tags.
Here is the result
http://kdelchev.com/index.php?p=73