PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
kinabaloo
Forum Commoner
Posts: 35 Joined: Tue Jul 28, 2009 11:20 pm
Post
by kinabaloo » Tue Jul 28, 2009 11:25 pm
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;
}
lordrt
Forum Commoner
Posts: 34 Joined: Sun Jul 19, 2009 11:44 pm
Post
by lordrt » Tue Jul 28, 2009 11:43 pm
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
bala_1225
Forum Commoner
Posts: 29 Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india
Post
by bala_1225 » Tue Jul 28, 2009 11:44 pm
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...";
?>
kinabaloo
Forum Commoner
Posts: 35 Joined: Tue Jul 28, 2009 11:20 pm
Post
by kinabaloo » Tue Jul 28, 2009 11:45 pm
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
kinabaloo
Forum Commoner
Posts: 35 Joined: Tue Jul 28, 2009 11:20 pm
Post
by kinabaloo » Tue Jul 28, 2009 11:48 pm
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
kinabaloo
Forum Commoner
Posts: 35 Joined: Tue Jul 28, 2009 11:20 pm
Post
by kinabaloo » Tue Jul 28, 2009 11:50 pm
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?
kinabaloo
Forum Commoner
Posts: 35 Joined: Tue Jul 28, 2009 11:20 pm
Post
by kinabaloo » Tue Jul 28, 2009 11:56 pm
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 ??
bala_1225
Forum Commoner
Posts: 29 Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india
Post
by bala_1225 » Wed Jul 29, 2009 12:04 am
<?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
kinabaloo
Forum Commoner
Posts: 35 Joined: Tue Jul 28, 2009 11:20 pm
Post
by kinabaloo » Wed Jul 29, 2009 12:15 am
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 ?
bala_1225
Forum Commoner
Posts: 29 Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india
Post
by bala_1225 » Wed Jul 29, 2009 12:17 am
<?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....
bala_1225
Forum Commoner
Posts: 29 Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india
Post
by bala_1225 » Wed Jul 29, 2009 12:22 am
str_replace('\n', '<br />', $aaa); use single quotes any try its....
kinabaloo
Forum Commoner
Posts: 35 Joined: Tue Jul 28, 2009 11:20 pm
Post
by kinabaloo » Wed Jul 29, 2009 12:31 am
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