Help spot error in this one line of php

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

Post Reply
kinabaloo
Forum Commoner
Posts: 35
Joined: Tue Jul 28, 2009 11:20 pm

Help spot error in this one line of php

Post 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;
    }
lordrt
Forum Commoner
Posts: 34
Joined: Sun Jul 19, 2009 11:44 pm

Re: Help spot error in this one line of php

Post 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
User avatar
bala_1225
Forum Commoner
Posts: 29
Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india

Re: Help spot error in this one line of php

Post 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.... :lol:

<?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

Re: Help spot error in this one line of php

Post 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
kinabaloo
Forum Commoner
Posts: 35
Joined: Tue Jul 28, 2009 11:20 pm

Re: Help spot error in this one line of php

Post 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.... :lol:

<?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

Re: Help spot error in this one line of php

Post 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.... :lol:

<?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

Re: Help spot error in this one line of php

Post 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 ??
User avatar
bala_1225
Forum Commoner
Posts: 29
Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india

Re: Help spot error in this one line of php

Post 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
kinabaloo
Forum Commoner
Posts: 35
Joined: Tue Jul 28, 2009 11:20 pm

Re: Help spot error in this one line of php

Post 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 ?
User avatar
bala_1225
Forum Commoner
Posts: 29
Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india

Re: Help spot error in this one line of php

Post 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....
User avatar
bala_1225
Forum Commoner
Posts: 29
Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india

Re: Help spot error in this one line of php

Post by bala_1225 »

str_replace('\n', '<br />', $aaa); use single quotes any try its....
kinabaloo
Forum Commoner
Posts: 35
Joined: Tue Jul 28, 2009 11:20 pm

Re: Help spot error in this one line of php

Post 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
Post Reply