Issue with dynamically generated javascript link with PHP - php

example link
returns PHP error:
syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';'
Any ideas? (Hope this question makes sense. I'm trying to fix someone else's code.)

Check that there's not a "<?" or "<?php" at the beginning of the file. This code assumes you're not already within a PHP block. If you are, then you'll have to adjust (remove it). Or, you'll need to add close ?> somewhere before this html, and a <?php after it...

Sorry about that guys, the problem was <?php echo val;?> instead of <?php echo $val;?>. Sometimes the eyes betray the mind...

Related

How do I get this PHP function to work with usort()?

I copied and pasted the piece of code below from http://php.net/manual/en/function.usort.php :
<?php
function cmp($a,$b)
{    
return strcmp($a["fruit"], $b["fruit"]);
}
$fruits[0]["fruit"] = "lemons";
$fruits[1]["fruit"] = "apples";
$fruits[2]["fruit"] = "grapes";
usort($fruits, "cmp");
while (list($key, $value) = each($fruits)) {
echo "\$fruits[$key]: " . $value["fruit"] . "\n";
}
?>
At first it gave some error about the $b variable. Now the new incessant error is:
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\testsort.php on line 4
I'm thoroughly confused as to the problem here.
When I copied and pasted the code, some strange characters were part of it. These were invisible within notepad but revealed by VS Code IDE. Removing them allowed the code piece work.

Template Parse Error SMF

I'm trying to add wikiplayer to my SMF Forum but I'm having a little trouble.. I'm trying to put this in my index.template.php:
<!-- Wikplayer http://www.wikplayer.com -->
<script type="text/javascript" src="http://www.wikplayer.com/code.js"
data-config="{'skin':'skins/wikfull/plainBlack/skin.css','volume':50,'autoplay':true,'shuffle':true,'repeat':1,'showcomment':false,'marqueetexton':true,'placement':'bottom','showplaylist':false,'playlist':[{'title':'It%27s%20The%20Most%20Wonderful%20Time%20Of%20The%20Year','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgFtb3EtjEic'},{'title':'All%20I%20Want%20For%20Christmas%20Is%20You','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DyXQViqx6GMY'},{'title':'Let%20It%20Snow','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmN7LW0Y00kE'},{'title':'Jingle%20Bell%20Rock','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DitcMLwMEeMQ%23t%3D36'},{'title':'Driving%20Home%20For%20Christmas','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DczhZbqpyBm8%23t%3D27'},{'title':'Merry%20Christmas%20Everybody','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0A8KT365wlA'},{'title':'Winter%20Wonderland','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSHE0Jo82_34%23t%3D56'},{'title':'Santa%20Baby','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dg7T0IK99ELs'},{'title':'It%27s%20Beginning%20To%20Look%20Alot%20Like%20Christmas','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcHh7pW29Fy8'},{'title':'Christmas','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5aw2yuYAKoE'},{'title':'Jingle%20Bells','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVKtOBLvPs5Q'},{'title':'Run%20Run%20Rudolph','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dl849CulLhGQ'},{'title':'Baby%20It%27s%20Cold%20Outside','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2Rhvtzzmq-Y'},{'title':'Rocking%20Around%20The%20Christmas%20Tree','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbnIqLlBwzrc%23t%3D15'},{'title':'Silent%20Night','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPGjByOI9Iqw'},{'title':'Holly%20Jolly%20Christmas','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKjiMMDZoKmY'},{'title':'Have%20Yourself%20A%20Merry%20Little%20Christmas','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DnZ6yQgBvuoI'},{'title':'Santa%20Claus%20Is%20Coming%20To%20Town','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSnA52s7qceM'},{'title':'Last%20Christmas','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DE8gmARGvPlI'},{'title':'Merry%20Christmas%20Everyone','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5PkUWkxGWj0'},{'title':'Shake%20Up%20Christmas','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJ-8VCL4uSUc'},{'title':'Deck%20The%20Halls','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D3-ykZUb3AEE'},{'title':'Carol%20Of%20The%20Bells%20(Pentatonix)','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVOGByYObUqE'},{'title':'Rudolph%20The%20Red%20Nose%20Reindeer','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0byH9h1ClBY'},{'title':'The%20Christmas%20Song','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSOszvL9lgSs'},{'title':'I%20Wish%20It%20Could%20Be%20Christmas%20Everyday','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZoxQ4Ul_DME'},{'title':'Do%20They%20Know%20It%27s%20Christmas','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1AcD7hho9fs'},{'title':'Feliz%20Navidad','url':'http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQ6ziiLE92Zg'}]}" ></script>
<!-- Wikplayer code end -->
But I'm getting this parse error all the time:
Template Parse Error!
There was a problem loading the /Themes/zone99/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.
You may want to try to refresh this page or use the default theme.
syntax error, unexpected T_STRING, expecting ',' or ';'
If I add this code outside the ?> right at the end it will work but then all the forum fonts seem bigger, too big... Can anyone guide me in simple terms to solve this problem? Thank you!
Also I will include my index.template.php # https://www.mediafire.com/?vj0jpbn7cae9of0
As you are getting parse error. That means you are missing colon ; or apostrophe ' somewhere. look for these if the problem persists try writing the script inside an echo statement.
echo '<script> your script here</script>'

Sprintf in php what am I doing wrong

I am new to PHP and I am somewhat understanding it. Now I am working on something but I keep getting a error message saying Parse error: parse error, unexpected T_ECHO in C:\wamp\www\mymoney.php on line 11. Now I am looking at line 11 and I don't see anything i am doing wrong. So I was woundering if someone can help me understand what I might be doing wrong thanks.
<html>
<head>
<title>money $</title>
</head>
<body>
<?php
$balance=55.75;
$newShirtCost=15.75;
$earns=20.00;
$buyscandybar=.55
echo "<p> Starting balance:" .sprintf("$%.2f",$balance)."</p>";
$balance= $balance -$newShirtCost;
echo "<p>Purchase: Clothing Store:".sprintf("$%.2f",$newShirtCost)."</p>";
$balance=$balance/2;
echo "<p>ATM Deposit:".sprintf("$%.2f",$earns)."</p>";
$balance=$balance-$buyscandybar;
echo "<p>Purchase: Gas Station:".sprintf("$%.2f",$buyscandybar)."</p>";
$balance=$balance
echo "<p>Ending Balance:".sprintf("$%.2f",$balance)."</p>";
?>
$buyscandybar=.55
Semicolon missed. When that error appears always check the line before too.
Also this makes no sense:
$balance=$balance
and it's without semicolon
Also you should separate your presentation by your logic
Use single-quotes strings or escape the $ with a \. Single-quotes strings are preferred of course since escaping = ugly.
"Parse error" means exactly parse error. It usually locates before the place, where interpreter points you. You've missed ";" at line 10.

Syntax error in printing image pointing to a link in php

The following line is supposed to print a list item which is a variable picture that points to a variable link
echo '<li><a href='http://www.twitter.com/'".$person."'>
<img src ="'.$person.'.jpg'.'"/></a></li>';
I am getting the following error though
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'
I am pretty sure I've screwed up the syntax in the a href part as I'm not quite sure how to handle the variables in the URLs...
Help is appreciated....Thanks!
Just use variable interpolation there.
echo "<li><a href='http://www.twitter.com/$person'><img src='$person.jpg'/></a></li>";
Why did you change the quote lol
echo "<li>
<a href='http://www.twitter.com/'".$person."'>
<img src ="'.$person.'.jpg'.'"/>
</a>
</li>";
Try using printf/sprintf; these two functions will make it a lot easier to deal with modifications to your code in the future as well as make it so that you're not "jumping in" and "jumping out" of quote sections a lot. It's a great way to avoid these kind of syntax problems with inline variables in double-quoted strings.
EDIT: The doc pages:
http://us3.php.net/manual/en/function.sprintf.php
http://us3.php.net/manual/en/function.printf.php

T_STRING error on line that just says <?php

So I'm writing a script in codeigniter, and I get the following error message:
Parse error: syntax error, unexpected T_STRING in /home/globalar/public_html/givinghusband.com/system/application/controllers/sizes.php on line 1
the only problem: the only thing on that line is this:
<?php
So I'm quite mysterified as to what's going on here? Have I typed PHP wrong or what?
There could be a problem with your editor when it updated the file. I just had this problem and the editor removed all line breaks.
If you are uncertain try opening your php file in another editor or use the Cpanel file manager to take a peak.
Or you may have an unterminated quote or statement on some previous line without an ending semicolon (;) . Check all files that are included before this one.
a bare <?php in the file leads to a parse error in php (don't ask). Try adding a whitespace or a newline after it
Sorry.A bit late but might helpful for others.Just looked at your question.Just use
<?
?>
instead of :
<?php
?>
and remove whitespaces/line breaks between your php open tag and class name .It will resolve this conflict.Ta

Categories