Parse error: syntax error, unexpected [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Currently I am getting
Parse error: syntax error, unexpected ''&i='' (T_CONSTANT_ENCAPSED_STRING) in /home/some/thing/index.php on line 45
which is the line below:
$content = '<iframe width="100%" height="70" frameborder="no" scrolling="no" src="http://example.com/player/audio.php?mp3=http://www.example.com/mp3embed-'.$secret.'.mp3''&i='.$row['image'].'&s='.$songz.'&a='.$artistz.'"></iframe>';
I am not completely sure what I am doing wrong here but I feel like what ever it is sort of indicates that i'm a goofy goober.

Change:
$content = '<iframe width="100%" height="70" frameborder="no" scrolling="no" src="http://example.com/player/audio.php?mp3=http://www.example.com/mp3embed-'.$secret.'.mp3''&i='.$row['image'].'&s='.$songz.'&a='.$artistz.'"></iframe>';
To:
$content = '<iframe width="100%" height="70" frameborder="no" scrolling="no" src="http://example.com/player/audio.php?mp3=http://www.example.com/mp3embed-'.$secret.'.mp3&i='.$row['image'].'&s='.$songz.'&a='.$artistz.'"></iframe>';
You can't just end and start a string like that without some sort of concatenation in between.

Ty changing
$content = '<iframe width="100%" height="70" frameborder="no" scrolling="no" src="http://example.com/player/audio.php?mp3=http://www.example.com/mp3embed-'.$secret.'.mp3''&i='.$row['image'].'&s='.$songz.'&a='.$artistz.'"></iframe>';
to
$content = '<iframe width="100%" height="70" frameborder="no" scrolling="no" src="http://example.com/player/audio.php?mp3=http://www.example.com/mp3embed-'.$secret.'.mp3&i='.$row['image'].'&s='.$songz.'&a='.$artistz.'"></iframe>';

Related

How to embed if in an echo and returning an <iframe>?

I am trying to use if in an echo with the ternary operator, but instead of a value, when if turns true it should display an iframe
echo(...'.((!$artArr[$count]["Longitude"] == null &&
!$artArr[$count]["Latitude"] == null)?<iframe width="425" height="350"
frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
src="https://www.openstreetmap.org/export/embed.html?bbox='.$artArr[$count]["Longitude"].'%2C'.$artArr[$count]["Latitude"].'%2C'.$artArr[$count]["Longitude"].'%2C'.$artArr[$count]["Latitude"].'&layer=mapnik&marker='.$artArr[$count]["Latitude"].'%2C'.$artArr[$count]["Longitude"].'"
style="border: 1px solid black">:.')

Passing PHP variable into URL

I have the code:
echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=266%20Orms%20St%20Providence%20RI&key=mykey" allowfullscreen> </iframe>' ;
I would like to pass the variable $street into the url, after q=, such as:
src="https://www.google.com/maps/embed/v1/place?q=$street&key=mykey
The map is showing but the actual street from $street is not being recognized. Furthermore, how would I pass more than 1 variable? I tried passing $street and $city ,unsucessfully:
src="https://www.google.com/maps/embed/v1/place?q=$street+city&key=mykey
you're using single quotes, so you need to do concatenation:
echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=' . urlencode($street) . '" allowfullscreen> </iframe>';
You can try also this.
echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q='.$street.'" allowfullscreen> </iframe>';

PHP find and replace html attribute in string

I get iframe from some api and i hold this iframe in some var.
I want to search for "height" and change his value to something else. the same with "scrolling".
For example:
<iframe src="someurl.com" width="540" height="450" scrolling="yes" style="border: none;"></iframe>
After the php function the iframe will be:
we have change the "height" to 600px and "scrolling" to no
<iframe src="someurl.com" width="540" height="600" scrolling="no" style="border: none;"></iframe>
i have solution with this code:
$iframe = preg_replace('/(<*[^>]*height=)"[^>]+"([^>]*>)/', '\1"600"\2', $iframe);
the problem is that after the "preg_replace" run it remove all html attributes after the "height"
Thanks
You can use DOMDocument for it. Something like this:
function changeIframe($html) {
$dom = new DOMDocument;
$dom->loadHTML($html);
$iframes = $dom->getElementsByTagName('iframe');
if (isset($iframes[0])) {
$iframes[0]->setAttribute('height', '600');
$iframes[0]->setAttribute('scrolling', 'no');
return $dom->saveHTML($iframes[0]);
} else {
return false;
}
}
$html = '<iframe src="someurl.com" width="540" height="450" scrolling="yes" style="border: none;"></iframe>';
echo changeIframe($html);
With this method you can modify iframe as you want.
Thanks.
An example as you requested:
$str = '<iframe src="someurl.com" width="540" height="450" scrolling="yes" style="border: none;"></iframe>';
$str = preg_replace('/height=[\"\'][0-9]+[\"\']/i', 'height="600"', $str);
$str = preg_replace('/scrolling=[\"\']yes[\"\']/i', 'scrolling="no"', $str);
echo $str; // -> '<iframe src="someurl.com" width="540" height="600" scrolling="no" style="border: none;"></iframe>'

Why not working the preg replce in iframe?

I would like to embed youtube links, but I also would like to embed the links from ['url'].
I dosen't get any wrong php messange.
My php code is:
$search = '#<iframe(.*?)(?:href="https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch?.*?v=))([\w\-]{10,12}).*<\/iframe>#x';
$replace = '<iframe width="560" height="315" src="http://www.youtube.com/embed/$2" frameborder="0" allowfullscreen></iframe>';
$text = preg_replace($search, $replace, $text);
And the iframe:
echo ' <iframe class="video" allowfullscreen style="overflow-x: hidden; overflow-y: hidden;" width="658px" height="569" frameborder="0" src="'.$row['url'].$text.'"></iframe>' ;
I would like to fix this becouse now if you give a youtube link the output looks like this:
<iframe class="video" allowfullscreen="" style="overflow-x: hidden; overflow-y: hidden;" width="658px" height="569" frameborder="0" src="https://www.youtube.com/watch?v=dh-0jH4Rb7Y"></iframe>
Why don't just use:
$fullUrl = //put here anything you want, be it result from MySQL or $_POST
echo ' <iframe class="video" allowfullscreen style="overflow-x: hidden; overflow-y: hidden;" width="658px" height="569" frameborder="0" src="'.$fullUrl.'"></iframe>' ;
and decide what should $fullUrl be ahead of echoing? For preg_replace to work you can't echo, you need to assign it to variable first. And why you want to preg_replace something that you assign with variable by yourself? Waste of memory and time.

how to store in a variable in its script format as string using php

I want to store this script below as a variable using a text area form but when I do and echo the variable, the browser interprets the code. I don't want this, I just want to store the script "as is" in a variable so I can use that variable for further manipulation. any ideas how I can accomplish this using a text area form in php?
<img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&ASIN=B008EYEYBA&Format=_SL110_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=mytwitterpage-20" ><img src="http://www.assoc-amazon.com/e/ir?t=mytwitterpage-20&l=as2&o=1&a=B008EYEYBA" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
btw, below is the exact php variable that I want when the user put the script above in a text area.
$str = "<img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&ASIN=B008EYEYBA&Format=_SL110_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=mytwitterpage-20" ><img src="http://www.assoc-amazon.com/e/ir?t=mytwitterpage-20&l=as2&o=1&a=B008EYEYBA" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />";
any help is greatly appreciated. thanks
use like this
<?php
$str = '<img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&ASIN=B008EYEYBA&Format=_SL110_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=mytwitterpage-20" ><img src="http://www.assoc-amazon.com/e/ir?t=mytwitterpage-20&l=as2&o=1&a=B008EYEYBA" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />' ;
echo htmlentities($str);
?>
If you need to output your value in HTML, you need to replace your < and > with < and >. Best is to use htmlspecialchars() function for that.
Also you were told correctly that your string has unescaped quotes in it (replace inside quotes with \").

Categories