Hi Guys,

Need some help, I am a noob. I get the following error

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in E:\Xampplite\xampplite\htdocs\wordpress\wp-content\themes\wp-comfy\config.inc.php on line 133

Whenever I insert this code

$comfy['adblock3'] = '<script language="javascript"><!--
document.write('<scr'+'ipt language="javascript1.1" src="http://ads.intergi.com/addyn/3.0/5205/1402264/0/225/ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=[group];misc='+new Date().getTime()+'"></scri'+'pt>');
//-->
</script><noscript><a href="http://ads.intergi.com/adlink/3.0/5205/1402264/0/225/ADTECH;loc=300;key=key1+key2+key3+key4;grp=[group]" target="_blank"><img src="http://ads.intergi.com/adserv/3.0/5205/1402264/0/225/ADTECH;loc=300;key=key1+key2+key3+key4;grp=[group]" border="0" width="728" height="90"></a></noscript></a>'; // footer advertisement

    The error is being caused because you are using unescaped single quotes within single quotes.

    //bad
    $html = 'It's bad to not escape the single quote';
    //good
    $html = 'It\'s not bad if escaped';
    //you can use double quotes inside single without escaping
    $html = 'It\'s "ok" to do this.';
    //and the other way.
    $html = "It's \"ok\" to do this.  Doubles now need escaping but singles don't";
    

    Take a look at your code and escape the single quotes in your string.

      Hi,

      Thanks for the quick feedback. I have tried finding which line is causing the issue but to no avail. I am really bad at this. 🙁

        This is the portion that is giving you trouble. You have it all wrapped in single qoutes, so anyplace else you use a single quote it should be with a slash before it.

        document.write('<scr'+'ipt language="javascript1.1" src="http://ads.intergi.com/addyn/3.0/5205/1402264/0/225/ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=[group];misc='+new Date().getTime()+'"></scri'+'pt>');
        

        So it should look like:

        document.write(\'<scr\'+\'ipt language="javascript1.1" src="http://ads.intergi.com/addyn/3.0/5205/1402264/0/225/ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=[group];misc='+new Date().getTime()+'"></scri\'+\'pt>\');
        

        This will clear you of the parser error. Do this on your code though, don't copy and paste form the forum, as I'm haphazardly showing you what to do. Once you open a string with a ', everyone there after except for the last one needs a \ infront.

          Hi Thanks for the help. However, I tried doing what you said and another error crept up ( I didn't copy paste from the forum )

          document.write('<scr\'+\'ipt language="javascript1.1" src="http://ads.intergi.com/addyn/3.0/5205/1402264/0/225/ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=[group];misc=\'+new Date().getTime()+\'"></scri\'+\'pt>\');

          This is the error I am getting. Thanks for your patience.

          Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING in E:\Xampplite\xampplite\htdocs\wordpress\wp-content\themes\wp-comfy\config.inc.php on line 134

            You really need to read string functionality

            Every string literal must be delimted by the same thing on both sides of the string literal. Excluding heredoc and nowdoc syntax, that means either having " both before and after the string literal, or having ' both before and after the string literal. PHP interpretation of the string literal will differ depending on which delimiter you use and what the string contains.

            $string = "it is a string";
            $string = 'it is a string';
            
            $string = "it's a string";
            $string = 'it"s a string';  # works, but " shouldn't be used instead of ' in the english language
            
            # this also works, because we now I escape the first ' (otherwise the string would end
            # before the first ', i.e. after "it")
            $string = 'it\'s a string';
            
            $string = 'it\'s a "string"';
            $string = "it's a \"string\"";
            

            Also, use an editor with syntax highlighting (colorization of code) and it's suddenly very easy to see where string literals begin and end. This forum has syntax highlighting for php code found within php tags, for example

            echo "String's are not always properly "escaped" but it's easy to see this (the blue text)";
            
              Write a Reply...