jimfog Posted December 20, 2011 Share Posted December 20, 2011 I cannot find the syntax error in the following code: echo "<div><a href="$_SERVER['PHP_SELF']".?month= ". $prev_month . "&year= ". $prev_year; Is there a problem with the quotes? Link to comment Share on other sites More sharing options...
Don E Posted December 20, 2011 Share Posted December 20, 2011 Try this: echo "<div><a href=\"".$_SERVER['PHP_SELF']."?month= ". $prev_month ." &year= " .$prev_year. "\"</a></div>"; Link to comment Share on other sites More sharing options...
jimfog Posted December 20, 2011 Author Share Posted December 20, 2011 Ok, it worked, but why you inserted double quotes twice at the beginning and the end? Link to comment Share on other sites More sharing options...
Don E Posted December 20, 2011 Share Posted December 20, 2011 So that the href link is quoted in the way it's suppose to be. ie: <a href="http://www.w3schools.com"></a> The backward slashes for escaping ".I forgot to add the '>' above. Correction: echo "<div><a href=\"".$_SERVER['PHP_SELF']."?month= ". $prev_month ." &year= " .$prev_year. "\"></a></div>"; Link to comment Share on other sites More sharing options...
dsonesuk Posted December 20, 2011 Share Posted December 20, 2011 It would be better to use single quotes to surround text as in the html etc, then you would not need to escape the double quotes within that html echo '<div><a href="'.$_SERVER['PHP_SELF'].'?month='.$prev_month.' &year= '.$prev_year.'"'; echo '<div><a href="'.$_SERVER['PHP_SELF'].'?month='.$prev_month.'&year='.$prev_year.'"'; Link to comment Share on other sites More sharing options...
jimfog Posted December 20, 2011 Author Share Posted December 20, 2011 these quotes issue is very complicated. Here is another line who(again) i cannot make it right. echo '<div class="monthname"'>$monthNames[$cMonth - 1].'kkk'. $cYear'</div>'; The class name is in double quotes-where is the error here? Is it ok for the string 'kkk' the way it is? Link to comment Share on other sites More sharing options...
TheGallery Posted December 20, 2011 Share Posted December 20, 2011 The code you provided would work like this echo '<div class="monthname">' . $monthNames[$cMonth - 1] . 'kkk' . $cyear . '</div>'; Let me explain. When you display an HTML link using echo, you actually display a string that's why you have to enclose it in a single or double-quotes. But you also want to display some PHP variables. The dot (.) is connecting all the parts of the echo statement so you have to use it in both ends. For example echo 'string' . $variable . 'string'; . As you see, in your code you forgot to add the dot before $monthNames[$cMonth - 1] and what is more your single quote should go after > so that it is inside the string. I really hope i didn't make this more complicated for you. I am in a hurry, i'll probably be able to explain it more simple when i go home. Link to comment Share on other sites More sharing options...
jimfog Posted December 20, 2011 Author Share Posted December 20, 2011 Now i got it-at last. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.