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.
Related
i want to use a variable content (value) as a part of a variable name before the output
this is my code in other file:
<?php $vidooid1="fk16zv6mw2jj"; ?>
<?php $vidooid2="eztx3n90w8xs"; ?>
<?php $vidooid3="eztx3n90w8xs"; ?>
<?php $vidooid4="eztx3n90w8xs"; ?>
<?php $vidooid5="eztx3n90w8xs"; ?>
<?php $vidooid6="eztx3n90w8xs"; ?>
<?php $vidooid7="eztx3n90w8xs"; ?>
<?php $vidooid8="eztx3n90w8xs"; ?>
<?php $vidooid9="eztx3n90w8xs"; ?>
<?php $vidooid10="eztx3n90w8xs"; ?>
and this is the code in the actual file:
<?php $titlenumber="1"; ?>
<?php $vidoo="https://vidoo.tv/e/"; ?>
and this is the echo final result:
<?php echo $vidoo; ?><?php echo $vidooid; ?>
I want that when I change the value that is inside the $titlenumber then that it is also changed in number that is next to the $videoid <----just here (i want to rename the string by using titlenumber)
This would be far better implemented using arrays.
e.g.
<?php
$vidoos = array(
"fk16zv6mw2jj",
"eztx3n90w8xs",
"eztx3n90w8xs",
"eztx3n90w8xs",
"eztx3n90w8xs",
"eztx3n90w8xs",
"eztx3n90w8xs",
"eztx3n90w8xs",
"eztx3n90w8xs",
"eztx3n90w8xs"
);
$titlenumber = 0;
$vidoo="https://vidoo.tv/e/";
echo $vidoo.$vidoos[$titlenumber];
$titlenumber = 3;
echo "<br/>"; //line break, just for demo
echo $vidoo.$vidoos[$titlenumber];
?>
Note that arrays start their indexes at 0 by default, so if you can start titlenumber at 0 too, you can do it simply like I've shown. If not, shift the array as shown in this answer
BTW you don't have to write a new <?php on every line. Just write it once at the start of the section of PHP, and close it once with ?> at the end. Lines in between only need to end with ;.
You can use concatenation as the following example shows:
$iterator = 1;
$variableName = 'vidooid';
$vidooid1 = 'some value';
echo ${$variableName . $iterator}; // outputs 'some value'
As the others said before, you should learn how to use arrays with PHP. The above shown solution is okay, but should not be used when you can use arrays instead.
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']);
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); ?>
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.