This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Reference - What does this error mean in PHP?
I keep on getting a "Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in..."
Here's the line thats causing the problem, not sure whats going on here?
$text = "<script>window.setInterval(function(){$('#liveData').load('liveUpdate.php');}, 1000);</script>";
Thanks in advance
You should escape $ in your $text
$text = "<script>window.setInterval(function(){\$('#liveData').load('liveUpdate.php');}, 1000);</script>";
Or you just use single quote.
Because $ in double quote will be followed by a php variable name, $(XXXX is an invalid PHP variable.
So the best way is to separate javascript (jquery) into a .js file.
Try this,
$text = '<script>window.setInterval(function(){$("#liveData").load("liveUpdate.php");}, 1000);</script>';
$text = '<script>window.setInterval(function(){$("#liveData").load("liveUpdate.php");}, 1000);</script>';
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 months ago.
Just started learning PHP out of curiosity. Currently going through all basic fundamentals in PHP and that's when I came across this function define that we do use to define variables with constant values. However, instead of showing me an expected output, it's giving me unexpected result. Can anybody help me?
define('HOST', 'localhost'); // syntax error, unexpected identifier "define", expecting "," or ";"
define('USER', 'root');
With the limited information given in this post, i only see two point where the issue might hide.
You forgot to start your php code with a <?php start tag
You have some php code above the snippet you posted that is missing it's ;(semicolon) on the end of it's line. Good hunting :-)
Hope this helps :-)
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I'm trying to use a shortcode in a php file using the do_shortcode function but I keep getting a syntax error in the shortcode part.
This is the actual error:
PHP Syntax Check: Parse error: syntax error, unexpected 'success'
(T_STRING), expecting ',' or ')' in your code on line 1
I tried to edit the code myself and tried to fix it using several syntax help websites.
<?php echo do_shortcode("[epcl_box type="success"]test[/epcl_box]"); ?>
I am not sure why I get the error message.
Wrong use of quotes:
<?php echo do_shortcode("[epcl_box type="success"]test[/epcl_box]"); ?>
^ ^ ^ ^
Escape the inner quotes:
<?php echo do_shortcode("[epcl_box type=\"success\"]test[/epcl_box]"); ?>
^^ ^^
... or use single quotes:
<?php echo do_shortcode('[epcl_box type="success"]test[/epcl_box]'); ?>
^ ^
You are using Double quotes in type="success" you have to use single quote instead as it is breaking your string:
<?php echo do_shortcode("[epcl_box type='success']test[/epcl_box]"); ?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I place to the php line a large piece of html code with javascript inserts (with jQuery) in which $ symbols is present.
<?php
$site = <<<SITE_CODE
setTimeout(function(){$(g_utils._f().menu.current_id).trigger('click')}, g_utils.effects.animation(g_utils._f().animation.events.loading, 'delay2'));
SITE_CODE;
echo $site;
?>
PHP takes this as a variable and produces an error.
Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$'
in D:\site\index.php on line 328
Tell me how to get rid of this problem?
If you single quote the EOL string it will not evaluate any variable:
$site =
<<<'SITE_CODE'
setTimeout(function(){$(g_utils._f().menu.current_id).trigger('click')}, g_utils.effects.animation(g_utils._f().animation.events.loading, 'delay2'));
SITE_CODE;
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I have an array
$array = ['first'=>'hi','second'=>'bye'];
Why following syntax is not working
echo " i wanna print $array['first']";
The error message is
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING) in
But when I tried
echo "i wanna print $array[first]";
did work fine.
So can someone explain what difference single quotes (') making here. And what does above error really mean, any ideas?
here php will not able to parse the multi dimension array from double quote string, to acheive same functionality you have to enquote the array variable inside {} brackets.
Try below line of code it will work without error.
echo " i wanna print {$array['first']}";
I hope this help you in understanding.
Use:
echo "i wanna print ".$array['first'];
Instead of
echo " i wanna print $array['first']";
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I am trying to fopen() a debugging text file, which I have simply named debug.txt and put it on my desktop. I am using PHP. My code is simply
$debug_file = fopen( "C:\\Users\\joe\\Desktop\\debug.txt", "w" );
I keep getting this error
Parse error: syntax error, unexpected '$debug_file' (T_VARIABLE) ` on line 755, which is the line of code above.
I have checked the code before this line for a missing semicolon, as that often is the source of a syntax error, but the previous code is fine. If I comment out my one line of code, the PHP file no longer gives a syntax error.
I was thinking that there is something wrong with the way I write the string literal file path to open. I have tried to make it ok by escaping the backslashes. I'm using Windows 10. But that hasn't fixed the problem. For the life of me I can't figure out what the syntax error is.
Thanks for any help.
EDIT: As requested, the previous lines of code are:
add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){
return;
}
The problem is the line(s) above, you either didn't end it with a semicolon or there's an open bracket, or something along those lines.