can you guys help me out with this, it should be easy but after 6 hours of work its frying my brain.
echo '<img src="', $webadd['data']['0']['address'], '"/>;
I just want it to be like:
<img src="http://www.image.com" />
the variable in the middle is the web address.
echo '<img src="'.$webadd['data']['0']['address'].'"/>';
echo "<img src='{$webadd['data']['0']['address']}'/>";
This should work:
echo '<img src="' . $webadd['data']['0']['address'] . '" />';
echo "<img src=\"" . $webadd['data']['0']['address'] . "\" />";
Consider adding spaces around the dots for readability.
You missed . by ,
Try this:
echo '<img src="'. $webadd['data']['0']['address'].'"/>;
or
echo "<img src=".'{$webadd['data']['0']['address']}'."/>";
TC lost to add qoutes to the end. Its works fine http://3v4l.org/5JCNc :)
$webadd['data']['0']['address'] = 'http://www.image.com';
echo '<img src="',$webadd['data']['0']['address'],'"/>';
See Example #1(separate by commas) from http://www.php.net/manual/en/function.echo.php.
Related
const EMOJI = [
":lol" => "http://localhost/chat/emoji/0046.gif",
":D" => "http://localhost/chat/emoji/0055.gif"
]
i want to use
EMOJI[:lol]
in src can anybody tell me how should i use it ?
case ":lol":
echo "<img src='EMOJI[:lol]' width='32' height='32'>";
break;
You have to escape quotes here. You can use like this:
echo "<img src='".EMOJI[':lol']."' width='32' height='32'>";
Just like that:
echo "<img src='" . EMOJI[':lol'] . "' width='32' height='32'>";
Array key should be integer or string so you should use EMOJI[':lol'] instead of EMOJI[:lol];
Example
case ":lol":
echo "<img src='".EMOJI[':lol']."' width='32' height='32'>";
break;
Okay so i was wondering how i echo a variable from a database that i already have connected to a php script so basicly it would be like
echo '<img src="blablabla.com/VARIABLENAMEHERE" />'
Use double quotes, and then variables will be expanded inside the string:
echo "<img src='blablabla.com/$variable' />";
Or user string concatenation:
echo '<img src="blablabla.com/' . $variable . '" />';
you can use double quotes as the double quotes evaluates the variable inside.
echo "<img src='blablabla.com/$variablename' />";
but if you insist using single quote you can use concatenation.
echo '<img src="blablabla.com/' . $variablename . '" />';
I want to echo these two strings. This is my current code:
echo str_replace(array_keys($swears), array_values($swears), $main).<br />;
echo str_replace(array_keys($swears), array_values($swears), $post).<br />;
But it produces this error:
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\new\new.php
Please let me know your feedback.
Use this instead since you have to use quotes for displaying HTML tags:
echo str_replace(array_keys($swears), array_values($swears), $main)."<br />";
echo str_replace(array_keys($swears), array_values($swears), $post)."<br />";
echo str_replace(array_keys($swears), array_values($swears), $main) . '<br />';
Ths is a string, so it has to be quoted.
echo str_replace(array_keys($swears), array_values($swears), $main). '<br />';
This code is giving a syntax error. can anyone tell me where is the problem? thanks in advance.
echo "<div class='cvtitle'><div><a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html"><b>".html_entity_decode(substr($video['video_title'],0,100))."..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>".html_entity_decode(substr($video['video_desc'],0,100))."</span></div><div class='cvviews'> View Count: <b>".$video['views']."</b></div></div></div>";
You have to do escaping. Instead of:
echo 'some text' . "aaaa"aaaa";
write:
echo 'some text' . "aaaa\"aaaa";
Rewrite your example to something like this:
echo "<div class='cvtitle'><div><a class=\"bloc_ca\" href=\"" . $video['video_id']
. '_' . str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20))
. '.html"><b>'
. html_entity_decode(substr($video['video_title'],0,100))
. "..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>"
. html_entity_decode(substr($video['video_desc'], 0, 100))
. '</span></div><div class="cvviews"> View Count: <b>'
. $video['views']
. '</b></div></div></div>';
p.s. code is a bit hard to read. Try only using one type of quotes to wrap around string and then another one can be used safely inside of that string.
Also - remember - if you wrap your string in ' or " - you have to escape this character inside of the string by adding backslash in front of it: \
http://php.net/manual/en/language.types.string.php
echo '<div class=\'cvtitle\'><div><a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html"><b>"'.html_entity_decode(substr($video['video_title'],0,100))."..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>".html_entity_decode(substr($video['video_desc'],0,100))."</span></div><div class='cvviews'> View Count: <b>".$video['views']."</b></div></div></div>";
There. You had some escaping issues. You were starting some strings with ' and ending them either with " or you were accidentally closing them without escaping
It is a classic case of mixing double quotes and single quotes, and forgetting to escape characters.
The string you return also seems to contain one extra </div>
echo '<div class="cvtitle">
<div>
<a class="bloc_ca" href="'. $video['video_id'] . '_' . str_replace(' ','-',substr(html_entity_decode($video['video_title']),0,20)) . '.html">
<b>' . html_entity_decode(substr($video['video_title'],0,100)) . "..</b></a>
</div>
<div class='cvdisc'>
<span style='word-break:wrap'>" . html_entity_decode(substr($video['video_desc'],0,100))."</span>
</div>
<div class='cvviews'>
View Count: <b>".$video['views']."</b>
</div>
</div>";
I'm getting this code:
echo "
".html_entity_decode(substr($video['video_title'],0,100))."..
".html_entity_decode(substr($video['video_desc'],0,100))."
View Count: ".$video['views']."
";
foreach($ret as $object)
{
$res = $object->...;
$img_src = $res[0]->src;
echo $img_src . '<br />';
echo str_replace("&size=2", "", $img_src) . '<br /><br />';
}
$img_src ~ 'http://site.com/img.jpg&size=2'
And I have to receive same link but without &size=2. Why doesn't work my last line in code. It shows the same url.
Are you absolutely certain there are any goofy unprintable characters in your source string? Try debugging with this:
printf("%s\n", join(':', str_split($img_src)));
And make sure you really have &size=2 in your string. If you see two consecutive colons, you've got something like a \0 or some other character mucking up the works in the middle of your string.
Seems to work on this end:
http://site.com/img.jpg&size=2
http://site.com/img.jpg
from
<?php
$img_src = 'http://site.com/img.jpg&size=2';
echo $img_src.'<br />';
echo str_replace("&size=2", "", $img_src).'<br/><br/>';
?>
use preg_replace:
$c=preg_replace("/&size=2/","",$img_src);
Example of usage
<?php
$sr="http://site.com/img.jpg&size=2";
echo preg_replace("/&size=2/","",$sr);
?>
This will output
http://site.com/img.jpg