hi friends why this php string error ?
echo '<div id="album_list">' . $i . ' ' . $v['album_name']. '</div>';
You have some missing single quotes.
echo '<div id="album_list">' . $i . ' ' . $v['album_name']. '</div>';
// you need a single quote here ^ ^ and here
You are missing a single-quote after album_pix/ and before the closing bracket.
echo '<div id="album_list">' . $i . ' ' . $v['album_name']. '</div>';
Single quote the string with the double quotes and attributes
Single space and concatenate with the period .
Change $var['key'] to $var, or $var["key"]
I'd change your variable names to reduce the confusion. As someone said above syntax highlighting will turn all the strings one color, and the variables another. Stack Overflow even displays code as such.
<?php
$v_id = $v['id'];
$v_album_name = $v['album_name'];
echo '<div id="album_list">' . $i . ' ' . $v_album_name . '</div>';
?>
Related
Im echoing some data from a database using PHP. However the data is too close together and needs a space in between each one.
while($book = mysql_fetch_array($books)) {
echo '<div>'
.$book['title']
.$book['author']
.$book['genre']
.$book['price']
.$book['availability']
.'</div>';
}
Is their a way to print a break maybe after each one to give a space.
Cheers
You can print it as html entity :
echo '<div>'
.$book['title'] . ' '
.$book['author'] . ' '
.$book['genre'] . ' '
.$book['price'] . ' '
.$book['availability']
. '</div>';
yes, and the answer is shown below
while($book = mysql_fetch_array($books)) {
echo '<div>'
.$book['title']." "
.$book['author']." "
.$book['genre']." "
.$book['price']." "
.$book['availability']." "
.'</div>';
}
To add my five cents )
while($book = mysql_fetch_array($books)) {
echo "<div>{$book['title']}
{$book['author']}
{$book['genre']}
{$book['price']}
{$book['availability']}</div>";
}
You may use the curly syntax in the double quoted strings:
echo "<div>{$book['title']} {$book['author']} {$book['genre']} {$book['price']} {$book['availability']}</div>";
When a string is specified in double quotes or with heredoc, variables
are parsed within it.
Hi straight forward question really. I have a search function in php that prints out the required information from a data base. But it prints it out as one word. I don't want a line break...just a space between words. I've googled and checked this forum for answers but can't seem to find any.
The code works and does as it is required but it doesn't look neat.
Instead of: ID Job Title Job Description Job location Job Category
it looks like this:
IDJobTitleJobDescriptionJoblocationJobCategory
This is part of my php code.
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo
'<p>'
. $results['id']
. $results['job_title']
. $results['job_description']
. $results['job_location']
. $results['job_category']
. '</p>';
Please note I want it in one line, not line breaks. Thanks.
You have to echo the space like this .' '.
Or in your Case just replace your code with this.
echo
'<p>'
. $results['id']
.' '. $results['job_title']
.' '. $results['job_description']
.' '. $results['job_location']
.' '. $results['job_category']
.' '. '</p>
echo '<p>'
.$results['id'] . ' '
. $results['job_title'] . ' '
. $results['job_description'] . ' '
. $results['job_location'] . ' '
. $results['job_category'] . ' '
. '</p>';
I want to create an HTML Message to send an email in PHP.
$message = $mess0 . "</br>" . $mess1 . "</br>" . $mess2 . "</br>" . $mes1 . "</br></br>" . $mes2 . "</br>" . $mes23 . "</br></br>" . $mes3 . "</br></br>" . $mes4 . "</br>" . $mes5 . "</br>" . $mes6 . "</br>" . $mes7 . "</br>" . $mes8 . "</br>" . $mes9 . "</br></br>" . $mes10 ;
$message = <html><body><p>$message</p></body></html>;
Here are some variables.
I am getting the following error.
Parse error: syntax error, unexpected '<' in /home/thevowaa/public_html/iphoneapp/webservice/file.php on line 214
Add HTML tags between double quotes.
$message = "<html><body><p>".$message."</p></body></html>";
Where are the double quotes see below
$message = "<html><body><p>$message</p></body></html>";
There are two possible ways to hold HTML in PHP variable. You can use single quote or double quotes. You also need to put a dot(.) before and after single/double quotes. Your PHP string could be constructed in following two ways:
$message = '<html><body><p>'.$message.'</p></body></html>';
or like this,
$message = "<html><body><p>".$message."</p></body></html>";
Also, use of single quotes(') is encouraged in PHP coding because it's doesn't clash with javascript or css double quotes(") when constructing html pages using PHP.
For more information on usage of quotes in PHP, check out this stackoverflow answer
I was making a school assignment with involves a shoutbox. A found great tutorial wich uses jquery,ajax,mysql and php. Now i run into a little problem with the following sentence:
$result .= "<li><strong>".$row['user']."</strong><img src="\" alt="\"-\"" />".$row['message']." <span class="\"date\"">".$row['date']."</span></li>";}
I was wondering if anybody could find out why it gives errors. So far I came to this conclusion $row['message'] and then it thinks the rest of the code as a string. So it probably is a apostrophe problem.
Just for the sake of making your life easier: use ' for the php and " for html like this:
$result .= '<li><strong>'.$row['user'].'</strong><img src="" alt=""/>'.$row['message'].' <span class="date">'.$row['date'].'</span></li>';
Pretty sure you should get the idea.
$result .= "<li><strong>{$row['user']}</strong><img src='http://www.' alt='My Alt Tag' />{$row['message']}<span class='date'>{$row['date']}</span></li>";
You're confusing yourself by coming in and out of quotations - you can wrap variables with {} to force the interpolation in such cases.
$result .= "<li><strong>".$row['user']."</strong><img src='' alt='-'/>".$row['message']." <span class='date'>".$row['date']."</span></li>";}
Avoid using " inside of the string - it is easy to forget about escaping special chars. Instead of " use '.
Besides - you use " only when there is any PHP parsing necessary within this string. E.g.
$var1 = 1;
$test = "$var1"; //evaluates to '1'
$test = '$var1'; //evaluates to '$var1'
It appears that you are attempting to escape quotes and making your job harder. A great feature in PHP for HTML output is using quoted strings so that you don't have to worry about escaping double quotes. Please reference the PHP Manual for Strings.
In other words your line becomes:
$result .= '<li><strong>' . $row['user'] . '</strong><img src="" alt="-" />' . $row['message'] .
'<span class="date">' . $row['date'] . '</span></li>' .
'<li><strong>' . $row['user'] . '</strong><img src="" alt="-" />' . $row['message'] .
'<span class="date">' . $row['date'] . '</span></li>';
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']."
";