Page 1 of 1
Help spot error in this one line of php
Posted: Tue Jul 28, 2009 11:25 pm
by kinabaloo
Hope someone can point out the error in the niddle line here (line 3 with str_replace),
If line 3 is commented out it works fine, but i really need to make the replacements work.
Is the problem that $aaa is not of type string/text ?
Code: Select all
function onGetContent( $editor ) {
$aaa = "document.getElementById( '$editor' ).value;\n";
$aaa = str_replace("\n", "<br />", $aaa);
return $aaa;
}
Re: Help spot error in this one line of php
Posted: Tue Jul 28, 2009 11:43 pm
by lordrt
kinabaloo wrote:Hope someone can point out the error in the niddle line here (line 3 with str_replace),
If line 3 is commented out it works fine, but i really need to make the replacements work.
Is the problem that $aaa is not of type string/text ?
Code: Select all
function onGetContent( $editor ) {
$aaa = "document.getElementById( '$editor' ).value;\n";
$aaa = str_replace("\n", "<br />", $aaa);
return $aaa;
}
Try to do display which values $aaa has after you do the document.getElement...
like
echo $aaa
Re: Help spot error in this one line of php
Posted: Tue Jul 28, 2009 11:44 pm
by bala_1225
Hi there is no error in your code...plz chk it again....
for eg. run this one you will get an idea....
<?php
echo "<strong>Before String Replace : </strong>".$aaa = "document.\ngetElementById\n( 'txtusername' ).value;\n";
echo "<br><strong>After String Replace : </strong>".$aaa = str_replace("\n", "<br />", $aaa);
echo "Its working properly...";
?>
Re: Help spot error in this one line of php
Posted: Tue Jul 28, 2009 11:45 pm
by kinabaloo
lordrt wrote:kinabaloo wrote:Hope someone can point out the error in the niddle line here (line 3 with str_replace),
If line 3 is commented out it works fine, but i really need to make the replacements work.
Is the problem that $aaa is not of type string/text ?
Code: Select all
function onGetContent( $editor ) {
$aaa = "document.getElementById( '$editor' ).value;\n";
$aaa = str_replace("\n", "<br />", $aaa);
return $aaa;
}
$aaa is the text from a form textarea.
Try to do display which values $aaa has after you do the document.getElement...
like
echo $aaa
Re: Help spot error in this one line of php
Posted: Tue Jul 28, 2009 11:48 pm
by kinabaloo
bala_1225 wrote:Hi there is no error in your code...plz chk it again....
for eg. run this one you will get an idea....
<?php
echo "<strong>Before String Replace : </strong>".$aaa = "document.\ngetElementById\n( 'txtusername' ).value;\n";
echo "<br><strong>After String Replace : </strong>".$aaa = str_replace("\n", "<br />", $aaa);
echo "Its working properly...";
?>
i will try. thanks
might be later code objecting to the html tags
Re: Help spot error in this one line of php
Posted: Tue Jul 28, 2009 11:50 pm
by kinabaloo
bala_1225 wrote:Hi there is no error in your code...plz chk it again....
for eg. run this one you will get an idea....
<?php
echo "<strong>Before String Replace : </strong>".$aaa = "document.\ngetElementById\n( 'txtusername' ).value;\n";
echo "<br><strong>After String Replace : </strong>".$aaa = str_replace("\n", "<br />", $aaa);
echo "Its working properly...";
?>
but what is this: 'txtusername' - a standard element?
Re: Help spot error in this one line of php
Posted: Tue Jul 28, 2009 11:56 pm
by kinabaloo
If replace normal text. If use html tags in str_replace, it fails.
Need to do something special to include html tags like this inside php ??
Re: Help spot error in this one line of php
Posted: Wed Jul 29, 2009 12:04 am
by bala_1225
<?php
echo "<strong>Before String Replace : </strong>".$aaa = "document.\ngetElementById\n( '$editor' ).value;\n";
echo "<br><strong>After String Replace : </strong>".$aaa = str_replace("\n", "<br />", $aaa);
echo "Its working properly...";
?>
sorry.... for eg...i use txtusername--for $editor
Re: Help spot error in this one line of php
Posted: Wed Jul 29, 2009 12:15 am
by kinabaloo
bala_1225 wrote:<?php
echo "<strong>Before String Replace : </strong>".$aaa = "document.\ngetElementById\n( '$editor' ).value;\n";
echo "<br><strong>After String Replace : </strong>".$aaa = str_replace("\n", "<br />", $aaa);
echo "Its working properly...";
?>
sorry.... for eg...i use txtusername--for $editor
str_replace("\n", "*", $aaa); works
str_replace("\n", "<br />", $aaa); does not
any ideas ?
Re: Help spot error in this one line of php
Posted: Wed Jul 29, 2009 12:17 am
by bala_1225
<?php
echo "<strong>Before String Replace : </strong>".$aaa = "document.\ngetElementById\n( '$editor' ).value;<center>";
echo "<br><strong>After String Replace : </strong>".$aaa = str_replace("<center>", "<br />", $aaa);
echo "Its working properly...";
?>
html tag will work... u can try it....
Re: Help spot error in this one line of php
Posted: Wed Jul 29, 2009 12:22 am
by bala_1225
str_replace('\n', '<br />', $aaa); use single quotes any try its....
Re: Help spot error in this one line of php
Posted: Wed Jul 29, 2009 12:31 am
by kinabaloo
bala_1225 wrote:str_replace('\n', '<br />', $aaa); use single quotes any try its....
This time it doesnt crash
but my breaks are lost somehow.
Must be somewhere else the problem.
Joomla using noeditor, btw
Thanks for your help