unable to do a simple regex :(
Posted: Wed Dec 19, 2007 1:39 am
problem:
since the $str is a multiline string. in javascript as expected the error comes unterminated string literal
for this i have to relpace all multiline charachers so that the javascript function parameter string should look like.
for that i am using the following line in php
neither of these are working
i tried '\r' , '\r\n' also instead of \n but no use any help
Code: Select all
//I have a multiline string. lets say.
$str = <<<EOS
php
is a
great
serverside
language
EOS;
echo '<input type="button" onlick=javascript:function("'.$str.'"); />';for this i have to relpace all multiline charachers so that the javascript function parameter string should look like.
Code: Select all
"php"+
"is a"+
"great"+
"serverlide"+
"language"
Code: Select all
preg_replace('/\n/',' "+\n" ',$str);
or
preg_replace('/\n/',' ',$str);
or
preg_replace('/\s/',' ',$str);i tried '\r' , '\r\n' also instead of \n but no use any help