Comma separated shortcode wordpress php - php

I want to separate several shortcodes by comma. Currently line is
<?php echo do_shortcode('[bangla_date]' . ',' . '[bangla_time]' . '.' . '[bangla_day]'); ?>
The output displayed on the website is a single line with no space in betwwen the shortcodes. Please help.

Try simply adding spaces:
<?php echo do_shortcode('[bangla_date]' . ', ' . '[bangla_time]' . ', ' . '[bangla_day]'); ?>
(',' => ', ')

Related

Unable to delete record from Solr if any white space there in PHP

$cat = 'tv - Episode';
$user_id = 1;
$delsolrobj = new SolrFunctions();
$delsolrobj->deleteSolrQuery("cat: ".$cat." AND sku:" . $user_id . " AND content_id:" . $_REQUEST['movie_id'] . " AND stream_id:" . $epData->id);
I have posted my solr delete PHP code. Above code I am getting this error message in my page.
'400' Status: Bad Request
I am sure that problem coming from $cat because there are some spaces.
I Googled found one solution they are saying to put your category within braces. I have done with this code:
$delsolrobj->deleteSolrQuery("cat: (".$cat.") AND sku:" . $user_id . " AND content_id:" . $_REQUEST['movie_id'] . " AND stream_id:" . $epData->id);
Now in my above line code working fine without any error message. But my record not delete from Solr.
please help me.
Try this query: (You can also use quotes when space is there)
$delsolrobj->deleteSolrQuery("cat:'".$cat."' AND sku:" . $user_id . " AND content_id:" . $_REQUEST['movie_id'] . " AND stream_id:" . $epData->id);
You have to escape the values properly, so that even if there is spaces or quotes, you don't run a badly generated query (i.e. if a category suddenly had ' OR -cat:foo or something similar in it).
If you're not using a Solr library (which should have an escape function available, you can use the ad hoc version:
function escapeSolrValue($string)
{
$match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' ');
$replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ ');
$string = str_replace($match, $replace, $string);
return $string;
}

Print a space in PHP

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.

Add space between words not line breaks in php

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>';

Help with PHP code

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']."
";

why this php string giving error?

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>';
?>

Categories