I'm trying to build a widget for a website that displays a random background image everytime the page is refreshed and i'm running into some trouble with string concatenation.
$display .= "<p class=\"ey-image-quote\" style\"background-image:url('".$img."')\">" . $this->quote . "</p>";
This returns a url without slashes (replaced by spaces) and i have not found a viable solution yet.
Is there any way to achieve this in php?
$display .= "<p class=\"ey-image-quote\" style=\"background-image:url('".$img."')\">" . $this->quote . "</p>";
You forgot = in style
Related
just print the square but not the image, dont know what is wrong, doesnt throw mistake.
Thanks
echo "<img src=\"img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
Nothing wrong in your code. Check if you have correct svg image or not at particular location. (inspect using chrome developer tool)
Check using Object tag or if your browser support or not. https://www.w3schools.com/html/html5_svg.asp
I would recommend to not mix strings with code vars. Always do proper concatenation:
$str = '<img src="/img/' . $numero[$i] . '.svg"';
$str .= ' alt="' . $numero[$i] . '"';
$str .= ' title="' . $numero[$i] . '"';
$str .= ' width="140" height="140">'. "\n";
echo $str;
your code seem right, try checking if the svg image is in the correct image path you placed
i tested with this and is working well
<?php
$numero = array('imagename', 'image alt', 'title');
echo "<img src=\"Images/$numero[0].svg\" alt=\"$numero[1]\" title=\"$numero[2]\" width=\"140\" height=\"140\">\n";
?>
thank you all, I discovered that it happened
I was missing a bar in front of the img
echo "<img src=\"/img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
instead of
echo "<img src=\"img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
I do not see any sense
So I am using the code that I got off W3C here: http://www.w3schools.com/php/php_ajax_database.asp
modified it to fit with my file names and database etc, however I am having a weird issue with echoing my responses to look correct.
For every product that collects from the product database it needs to print it in a section tag like so:
while($row = $result->fetch_assoc())
{
echo "<section class='sideWays'>" . $row['product_ID'] . " " . $row['product_name'] . " " . $row['description'] . " " . "<div class='colHeaderImageRight'>" . '<img src="'.$row['image'].'"">' . "</div>" . "</section>";
}
However this code isn't working anymore, the closest I have gotten is it to only display one and then breaks the rest.
the PHP echo is being returned into the following div tag
<article>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</article>
so I have tried changing my CSS to stuff like article > .txtHint > #sideWays or even just making the #sideWays css the same as .txtHint to skip the > #sideWays but nothing is working to display my CSS on the echo.
I'm not sure why but changing the keyword echo to print fixed the issue of it not recognising my html tags and applying the CSS to them.
I would like to link to another part of a php page. So $x is a value I've pulled from an array that is a hyperlink.
echo "<a href='#{$x}'>{$x}</a>" . " ";
However I am stuck in linking to the target id on the same page.
echo '<a id="$x">' . '<h2>'.strtoupper(str_replace("_", " ",($x))).' ' . 'offers'.'</h2>'.'</a>';
Sure when I hover over the link, it is passing the correct value of $x in the query string, but not linking to the because I am coding the target id part wrong.
Any help appreciated.
Volterony
If you want to visit a ID on on the page use href="#id"
echo '' . '<h2>'.strtoupper(str_replace("_", " ",($x))).' ' . 'offers'.'</h2>'.'';
Improved Code
echo '<h2>'.strtoupper(str_replace("_", " ",($x))). 'offers </h2>';
I am trying to grab the ID of my link from every single one and output it to a db which i will then use to go and scrape the actual page.
So i will grab the id, curl the page link then parse the details.
So far i have my links clickable, it's just trying to get the certain part of my links that is the hard part.
I have tried $_GET['id'] but this won't work as the id's are not in that format.
Here is the way my links are set out:
download.php/1000338/The%20Rise%20and%20Fall%20of%20Legs%20Diamond%20%5B1960%5D.avi.torrent
what i want to grab is the 1000338 part but i want it to do this for every single one and ofcourse they are not the same.
Any help is very much appreciated, thanks.
$link="download.php/1000338/The%20Rise%20and%20Fall%20of%20Legs%20Diamond%20%5B1960%5D.avi.torrent";
$x=explode('/',$link);
$id=$x[1];
demo:http://codepad.viper-7.com/cWYXKe
using your code:
$rss = simplexml_load_file('RSS FEED HERE');
echo '<h1>'. $rss->channel->title . '</h1>';
foreach ($rss->channel->item as $item) {
//echo the link echo '<h2>' . $item->title . "</h2>";
//echo the date echo "<p>" . $item->pubDate . "</p>";
//echo the description echo "<p>" . $item->description . "</p>"
$x=explode('/',$item->link);
$id=$x[1];
}
then use $id any way you like
i have a question in regards to the following.
i have the function
function print_link($link_num)
{
global $error_str;
if($link_num) {
$error_str .= "<img src='img/Move.png'/>$link_num"
;
}
which displays an image next to a number according to $link_num
i have created a folder with images assigned to this number ($link_num).
im trying to display an image without having the need to display $link_num and the image.
so far ive tried
$error_str .= "<a href=\"page.php?toloc=$link_num\"><img src="img/'.$link_num.'.png" />";
but i get an unexpected T_STRING error.
my knowlege of php is not so good, is there a way i can link the image directly from my folder according to $link_num?
i hope ive been clear.
thank you for reading.
You are mixing your " and ' within the code. The first " in the img tag is not being escaped properly and hence caused a parse error on the page try:
$error_str .= "<a href=\"page.php?toloc=$link_num\"><img src=\"img/".$link_num.".png\" />";
you have to escape the dot (.) in ".png":
$error_str .= "<a href=\"page.php?toloc=$link_num\"><img src="img/'.$link_num.'\.png" />";
But to make it more clear use only one type of ":
$error_str .= '<a href="page.php?toloc='.$link_num.'"><img src="img/'.$link_num.'.png" />';