I have the 2 following echos :
<?php echo $data->county; ?>
This one gives me datas like "florida", "california"... from the database
and
<?php echo lang(california); ?>
This one gives me a translation from a lang.php file, for example :
'california' => 'La californie'
I would like to place the $data->county in the lang echo, I tried the following with no success :
<?php echo lang(.$data->county.); ?>
What's the error ? Is it possible to echo in an echo ?
What made you think you needed the dots? Just pass it like any other argument:
<?php echo lang($data->county); ?>
<?php echo lang($data->county); ?>
Lose the .s, they're for concatenating strings. You're just passing a string variable.
Related
I am making static php and i want somthing like this (i am a php beginner :):
From this:
<?php $titleid="example title"; ?>
To this:
<?php $title="<?php echo $titleid; ?>"; ?>
To get this:
<h1><?php echo $title; ?></h1>
And then, the expected output is:
<h1>example title</h1>
I use this cause the variable $titleid is in other php file.
In this line
<?php $title="<?php echo $titleid; ?>"; ?>
You should not use the echo, since at that time you don't want any output. Also avoid the double <?php ?> brackets.
Just write that line as
<?php $title=$titleid; ?>
First, you open <?php tag only once in file. if you want get example title in your pages, you define this content one variable and then get result with echo :
Ex
<?php
$title = "<h1>example title</h1>";
echo $title;
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(' $postcode_coveringsRecord['postcode']) ?>
<?php echo htmlencode('. $postcode_coveringsRecord['postcode'].) ?>
<?php echo ' ''htmlencode('$postcode_coveringsRecord['postcode'])' ?>
<?php echo htmlencode(' ''$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']);
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
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.
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); ?>