creating a space before a variable including htmlencode str_repeat - php

I have a variable given to me by my cms
I want to add one space before that but have tried many things lol and all dont work, below is what I have tried so far.
<?php echo str_repeat('', 1) htmlencode('$postcode_coveringsRecord['postcode']) ?>
<?php echo htmlencode('&nbsp$postcode_coveringsRecord['postcode']) ?>
<?php echo htmlencode('. $postcode_coveringsRecord['postcode'].) ?>
<?php echo '&nbsp''htmlencode('$postcode_coveringsRecord['postcode'])' ?>
<?php echo htmlencode('&nbsp''$postcode_coveringsRecord['postcode']) ?>
How can I minipulate
where as the variable gives me one blank space prior to the variable content.
cheers for any input
emma

These ones should work
echo ' '.htmlencode($postcode_coveringsRecord['postcode']);
or
echo ' '.htmlencode($postcode_coveringsRecord['postcode']);

Related

how to access value which passed through url?

I have trying to access value of variable from one page to another by using following code:-
page1.php
<td>
echo $var12=$row['p_id'];
echo 'Received';
</td>
receive_branch_confirmation.php
<?php echo $_GET['prop_id']; ?>
My previous error solved but now it is just print ",$var12,"
please tell me where is my mistake
As you are using echo for displaying the a tag you no need to use echo or close and open php tags.
It is enough if you concatenate the variable that you are going to send.
$var12 = '2';
echo 'Received';
Then your URL will look like as follows
http://domain.com/receive_branch_confirmation.php?prop_id=2
And in the receive_branch_confirmation.php you can access the variable passed with the help of $_GET or $_REQUEST
<?php
echo 'Request Value: '.$prop_id = $_REQUEST['prop_id']; // this will result the output as 2
echo '<br>';
echo 'Get Value'.$prop_id = $_GET['prop_id']; // this will result the output as 2
?>
Output:
Request Value: 2
Get Value: 2
Another Example:
If the URL is http://domain.com/page.php?var1=apple
then if you need to access the variable as follows in page.php.
<?php
$u1 = $_GET['var1'];
$u2 = $_REQUEST['var1'];
echo $u1; //would output "apple"
echo $u2; //would output "apple"
?>
page1.php
<td>
<?php echo '<a href=receive_branch_confirmation.php?prop_id='.$var12.'>Received</a>'; ?>
</td>
receive_branch_confirmation.php
<?php
echo $_GET['prop_id'];
?>
It should be
Received
in html page and
<?php
echo $_GET['prop_id'];
?>
in php page
and always try to separate html from PHP
You need to update your page1.php as below
echo 'Received';
and get it like this
<?php
echo $_GET['prop_id'];
?>
Try this in html
<td>
<a href="receive_branch_confirmation.php?prop_id="<?php echo $var12;?>>Received</a>
</td>
in php side
<?php
echo $_GET['prop_id'];
?>
You need to change the $_GET value.
<?php
echo $_GET['prop_id'];
?>
Now it's looking for the prop_id instead of the value

Syntax for using echo inside an echo (wordpress slider)

this is the piece of code I'm not sure how to deal with:
<?php echo get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="InsertHere"]'); ?>
I simply want to insert the first echo instead of InsertHere. The first echo should output the content of a custom field. The second should recall the slider with the specific number inserted in the custom field. When trying different possibilities I only get errors.
Can anybody help?
Thank you :)
Don't echo the first value, use it directly inside your second echo.
<?php
echo do_shortcode('[smartslider2 slider="'.get_post_meta($post->ID, 'smartslider2', true).'"]');
?>
Or you can easily put that first value in a variable and use that variable in the second line
<?php $slider = get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="'.$slider.'"]'); ?>

Concatenation within echo of array

Very simple but this echo isn't returning anything. I want to concatenate 2 values from an included PHP array file so I don't have to write the code twice. What am I writing incorrectly?
<?php echo $lang['work' . 'title']; ?>
Among others I have tried
<?php echo $lang['work', 'title']; ?>
<?php echo $lang['work' 'title']; ?>
<?php echo $lang['work'], $lang['title']; ?>
Check out php array documentation.

Setting a php variable to html

I am setting the value of a php variable to some html. i.e.
$_img = 'hehehehehe';
The variable is then shown in html after a br tag. But it doesn't execute the html in it. Rather it displays it like hehehehehe. So, is there any problem in my code! How can i do this thing?
Here is the code that displays that IN HTML,
<?php if ($_item->getComment()): ?> <br/><?php echo $this->escapeHtml($_item->getComment(), array('b','br','strong','i','u')) ?> <?php endif; ?>
<?php
$string = 'Hehehe';
echo $string;
?>
This works fine! The html is 'executed' and the link is displayed.
From your comment....
Here is the code that displays that <?php if ($_item->getComment()):
?> <br/><?php echo $this->escapeHtml($_item->getComment(),
array('b','br','strong','i','u')) ?> <?php endif; ?>
As predicted by many people, it looks like you are encoding the value when you display it.
I don't know what the $this->escapeHtml function is doing exactly, but it would appear to be doing an HTML Encoding on the string.
The result being that any tag, for example <a> will be sent to the browser as <a> which the browser will display as <a>. The browser will not see it as a tag, and will therefore not treat it as one.
So the simple answer is: don't encode the HTML...
<?php echo $_item->getComment(); ?>
I suspect you are just echoing the variable.
You need use the 'htmlspecialchars' method such as below.
<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
?>

Extracting basic PHP echo from IF statement

The following code is for a Wordpress plugin, it displays points and tank of a user:
<?php
if(function_exists('cp_displayPoints') && $authordata->ID){
echo '<span class="cubepoints_buddypress">'; cp_displayPoints($authordata->ID); echo '</span>';
if(function_exists('cp_module_ranks_getRank')) echo ' <span class="cupepoints_buddypress_rank">'.cp_module_ranks_getRank($authordata->ID).'</span>';
}
?>
I am trying to extract these two echo functions from the If statement but only succeeded with one of them. I can echo the points like this:
<?php cp_displayPoints($authordata->ID); ?>
Works fine. Now I tried doing the same with the second echo:
<?php cp_module_ranks_getRank($authordata->ID); ?>
But it did not work. Obviously, there is some basic thing that I am missing here. Do you know what it is?
The first one likely prints directly to output, while the second returns its value. So, you need to echo() the second one, just as they're doing in your sample code:
<?php echo cp_module_ranks_getRank($authordata->ID); ?>

Categories