PHP echo and print Parse Error [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
MY code is quite simple.
<?php
echo "hello world";
?>
and i get this message
Parse error: syntax error, unexpected 'world' (T_STRING) in /usr/local/zend/apache2/htdocs/index2.php on line 2

I just copied the code from above on this page because it has the straight bar quotes instead of the curly quotes. I pasted this back into text editor... and wala! it work! thanks guys for the help!!! whoever said the idea about the quotes, i am one upping you or however this site works.

Related

Wordpress: Shortcode Error in PHP: syntax error, unexpected '1' (T_LNUMBER) [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
Hi I was told to put the following code into my footer PHP
<?php echo do_shortcode("[wpgmza id="1"]"); ?>
My acutal code:
<div class="col-lg-8"><?php echo do_shortcode("[wpgmza id="1"]"); ?> </div>
Im getting the following Error:
Your PHP code changes were rolled back due to an error on line 142 of file wp-content/themes/XXXX/footer.php. Please fix and try saving again.
syntax error, unexpected '1' (T_LNUMBER)
Why is this happening when most forums i read say to that following code?
You are not escaping the quotes in the string and so the string itself ends just before the 1.
What your code is seeing
<?php echo do_shortcode("string"1"string"); ?>
To fix you can change it to single quotes.
<?php echo do_shortcode('[wpgmza id="1"]'); ?>
Here is more info on escaping strings https://www.php.net/manual/en/language.types.string.php

Echo Inside of a PHP Include [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm quite new to PHP. I have created an array which I have included however when I need to echo a url which is in my settings array it just gives me the following error:
Parse error: syntax error, unexpected 'templateurl' (T_STRING) in C:\xampp\htdocs\index.php on line 15
Thanks for your help and time in advance.
Try this:
<?php include('hi.php'); echo $settings['templateurl'];?>
You need to include the file first and then you are able to retrieve the data from it.

PHP: if { } parse error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm using this to determine if a variable is set. I am not a beginner and normally, this works (it's not complicated either)...
if(isset($ok)) { 
[stuff happening]
}
This is the return:
Parse error: syntax error, unexpected '}' in firstlaunch.php on line 6
The thing is, that's that. My file is empty but for those few lines. I'm used to fixing those types of problems but I can't see why the error is coming since that's the only PHP on my page.
Ideas?
Thanks a lot!
++++++
Edit: the full script is:
<?php
$ok = isset($_GET['flag']);
if(isset($ok)) { 
}
?>
Ok guys, thanks a lot for the HEX editor suggestion, it worked: I had this thing between my { }:
 
Wonder where that came from... But now my file executes!
Thanks!

Syntax error: Unexpected T_String error in line 5 of the following code. [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
<?php
$db_name=“a7614252_booked”;
$mysql_user="a7614252_booked”;
$mysql_pass=“booked”;
$server_name="server38.000webhost.com”; //t_string error here.
$con=mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name)or die(‘Connection Error’.mysqli_connect_error());
?>
i have checked other responses on the same error but none of seem to be the answer to the problem here. Thank you.
use this code, Replace “ with " or '
<?php
$db_name="a7614252_booked";
$mysql_user="a7614252_booked";
$mysql_pass="booked";
$server_name="server38.000webhost.com"; //t_string error here.
$con=mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name)or die(‘Connection Error’.mysqli_connect_error());
?>
You need to replace all occurences of “ with " AND also the backticks
` by '. Otherwise PHP will interprete the latter as bash commands.
$db_name="a7614252_booked";
$mysql_user="a7614252_booked";
$mysql_pass="booked";
$server_name="server38.000webhost.com"; //t_string error here.
$con=mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name)or die('Connection Error'.mysqli_connect_error());

issue with php basic [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Parse error: syntax error, unexpected '<' in N:\ftp\compc\ac12mm\Practical 3 Files\myContacts.php on line 102
Any Idea what would be wrong with this please?
Please help this is really fustrating me, Im not very good at php
You cannot include HTML Code directly in your PHP code.
To fix, you must use a command like echo, print(), or break from your PHP Code. This would require a PHP end block:
} else {
?>
<TD>
Or:
} else {
echo "<TD>";
See more: http://php.net/manual/en/tutorial.firstpage.php

Categories