PDA

View Full Version : help with installer script...


TECK
06-25-2002, 06:10 AM
i need some help to builld a function to automatically replace the " and '.

here it is what i try to do:$ccode[1]='if (!$getperms[\'canviewothers\') {
show_nopermission();
}';
$ccode[2]='New code here...';

maketextareacode('FIND','cc',$ccode[1],'4','100');
maketextareacode('BELOW THIS, ADD','cc',$ccode[2],'10','100');i had to manually add a slash in front and at the end of canviewothers to dont get any parse errors...
what should i use to automatically replace the ' with a \'?
a str_replace should do?
$ccode[1]=str_replace("'","\'",$ccode[1]);

if i do this, i still get parse errors... what is the best aproach to eliminate the \' or \" problem?
thank you for reading this.

TECK
06-25-2002, 06:17 AM
hmm for some reason, the [code] and [php] removed my \ in front of the 'canviewothers'...?

test: \' \"
ok... the slash in front of ' is gone...

TECK
06-25-2002, 08:48 AM
i was reading about serialize/unserialize on php.net...
i still cant understand the mechanism. can you explain to me how it works?

Admin
06-25-2002, 10:04 AM
You can't. Even if you use str_replace on it, you still need to quote it as a string... think about it for a while.

You might want to use the Here Doc syntax, but you will still need to escape variables.

TECK
06-25-2002, 10:08 AM
i thought so... then, the only solution is the use that area as html code... thanks alot chen for your precious help.

Logician
06-25-2002, 10:38 AM
I have absolutely no idea what you are trying to achieve with this code but you can always "addslashes" your variable and then "stripslashes" it anytime you want. It seemed to me this is what you were asking, if not, sorry ignore me..

Admin
06-25-2002, 11:35 AM
Ok, take a look at this nakkid.

<?php

ob_start();
?>if (!$getperms['canviewothers') {
show_nopermission();
}<?php

$ccode[1] = ob_get_contents();
ob_end_clean();

?>

(ugly, I know, but it gets the job done)