Search code examples
phpstringif-statementparse-error

Getting syntax error in php


while using if statement as below and assigning values to two variable I'm getting below error. Parse error: syntax error, unexpected 'Guar' (T_STRING) in /home/..../.../something.php on line 158. below is the code of line 157 and 158. I know I need to use some escape character but I don't know how to implement it here. Please help me resolve this issue. Thanks.

Code:

if($crom_name== "Groundnut pods (raw)"){$guname="DUO/LGL ;L\UM sSFRLf";$hiname="D}\UO,L SL Ol,IM\";}
if($crom_name== "Guar"){$guname="U]JFZ";$hiname="S,:8Z";}

Solution

  • Your problem is this line

    if($crom_name== "Groundnut pods (raw)"){$guname="DUO/LGL ;L\UM sSFRLf";$hiname="D}\UO,L SL Ol,IM\";}
    

    You are escaping the final quote and therefore the line should be throwing an unterminated string constant error. You need to escape the backslash. You probably also want to escape the other backslash (the one before the U.

    if($crom_name== "Groundnut pods (raw)"){$guname="DUO/LGL ;L\\UM sSFRLf";$hiname="D}\\UO,L SL Ol,IM\\";}