I want to display everything what is in a url.
So if someone use test.php?test=yes&no=why
i want to show
test = yes
no = why
but when someone use test.php?bla=blala
i want to show
bla = blala
Is this possible?
Pretty print the $_GET variable.
<?php print_r($_GET); ?>
Try this:
foreach ($_GET as $key => $value) {
echo $key . " = " . $value
}
use this php script:
foreach($_GET as $key => $value){
echo $key . " = " . $value;
}
<?php var_dump( $_GET ); ?>
will echo out everything inside $_GET
<?php var_dump( $_REQUEST ); ?>
will do everything in both a $_POST and an $_GET
You can also try
<?php
$string = "Url Variables <br />";
foreach( $_REQUEST as $key => $value ){
$string .= $key." = ".$value." <br />";
}
echo $string;
?>
Related
Why can not I make an echo inside a textarea after doing a foreach? the echo happens yes, but everything comes in fragments, one line in each text area.
Why does not everything come out in the same text area?
$array = end($matches);
$array = array_unique($array, SORT_REGULAR);
foreach ($array as $strX) {
$strX = 'myprefix'.$strX.'<br>';
//echo $strX;
echo '<textarea>'.$strX.'</textarea>';
}
Concatenate the value and then echo into the textarea.
$value = null;
foreach ($array as $strX) {
$value .= 'myprefix'.$strX.PHP_EOL;
}
echo '<textarea>'.$value.'</textarea>';
https://3v4l.org/KZn2M
As I understood you so far. You just need to put the beginning tag of textarea before the for-loop. So your code would become:
$array = end($matches);
$array = array_unique($array, SORT_REGULAR);
echo '<textarea>';
foreach ($array as $strX) {
$strX = 'myprefix'.$strX.'<br>';
//echo $strX;
}
echo '</textarea>';
Try this, put textarea outsside loop
$array = end($matches);
$array = array_unique($array, SORT_REGULAR);
echo '<textarea>';
foreach ($array as $strX) {
$strX = 'myprefix'.$strX.'<br>';
//echo $strX;
}
echo '</textarea>';
with:
<?php
$data = file_get_contents("http://query.yahooapis.com/v1/public/yql?env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json&q=select%20*%20from%20yahoo.finance.historicaldata%20where%20startDate=%272014-01-01%27%20and%20endDate=%272014-01-10%27%20and%20symbol=%27YHOO%27");
$myArray = json_decode($data, true);
/*
echo "<pre>";
var_dump( $myArray );
echo "</pre>";
*/
echo $myArray['query']['results']['quote'][0]['Close']," DayX";
?>
i can read out the closing-number for the first day.
-> how can i read out ALL entries for 'Close'? -> in this example it would be:
echo $myArray['query']['results']['quote'][0]['Close']," Day1";
echo $myArray['query']['results']['quote'][1]['Close']," Day2";
echo $myArray['query']['results']['quote'][2]['Close']," Day3";
...
echo $myArray['query']['results']['quote'][6]['Close']," Day7";
You'll need to use a foreach loop to do that.
foreach ($myArray['query']['results']['quote'] as $k => $v) {
echo $v['Close'] . " Day" . ($k+1) . "<br />";
}
Having <br /> at the end of each line will add a line break, assuming this is being echoed to the browser;
I use this code to retrieve all the post request (refer below)
<?php
foreach ($_POST as $key => $value) {
$body .= $key . ": " . $value . '<br>';
}
echo $body;
?>
and there is a post data named "adminemail" and "cat", now what i want is to eliminate those two and print all the post data except those two. How to do that? any suggestions, recommendations and ideas, would love to hear. Thank you in advance.
option 1
unset($_POST['adminemail'],$_POST['cat']);
option 2
<?php
foreach ($_POST as $key => $value) {
if(!in_array($key,array('adminemail','cat'))){
$body .= $key . ": " . $value . '<br>';
}
}
echo $body;
?>
The following should work:
<?php
$arr = array_diff_key($_POST, array("adminemail" => 0, "cat" => 0));
$body = ""; // You must have this line, or PHP will throw an "Undefined variable" notice
foreach($arr as $key => $value){
$body .= $key . ": " . $value . "<br/>";
}
echo $body;
?>
I would like to assign an image to a variable in a PHP script so that I can make the image appear when I want to it to, by declaring the variable.
$FoodList = array_unique($FoodList);
if (!empty($FoodList)) {
foreach ($FoodList as $key => $value) {
// The variable would go here, so that image would appear
//next to each variable
echo "<li>" . $value . "<li>";
}
echo "</ul>";
}
Either you assign
$var = "img src="'your/pathto/image.ext'";
$var = "your/pathto/image.ext";
and echo it in html img code
The second method is more preferred
$FoodList = array_unique($FoodList);
if(!empty($FoodList)) {
foreach ($FoodList as $key => $value) {
//The variable would go here, so that image would appear
//next to each variable
$value = "<li>";
//Maybe you'll only display an image is a certain condition is met? If so, then...
if($condition == "parameter") {
$value .= "<img src='path/to/img' alt='img' />";
}
$value .= "</li>";
echo $value;
unset($value);
}
echo "</ul>";
}
$FoodList=array_unique($FoodList);
$img_path = 'images/example.jpg';
if(!empty($FoodList))
{
foreach ($FoodList as $key => $value)
{
echo "<img src='$img_path' />";
echo "<li>".$value."<li>";
}
echo "</ul>";
}
Use this:
echo "<li><img src='path_of_image/".$value."'/><li>";
Supposing that $value has the name of your image with extension of image.
<?php
$name="Adil";
echo $name;
$path="FB_IMG_1465102989930.jpg";
for($i=0;$i<44;$i++)
{
echo($i.'<br>') ;
if($i==10)
{
echo ".$path.";
echo "<img src ='".$path."'>";
}
}
?>
please insert a space before your image name :-
Example:-
$image_name="myphoto.jpg";
$image_path="./upload/ ".$image_name;
here I add a space after "./upload/(space)"
Store the image path into your MySql database.
call it from your HTML page as:-
<img src= '<?php echo $image_path;?>'width="200" height="200" alt=""/>
I am not able to understand the behaviour of the code :
Input :
<?php
function polldaddy_choices($choices) {
foreach ($choices as $choice) {
$answer = "<pd:answer>
<pd:text>" . $choice . "</pd:text>
</pd:answer>";
echo $answer;
}
}
$total_choices = array('yes' , 'no' , 'do not know');
$ans = polldaddy_choices($total_choices);
$xml = "world" . $ans . "hello" ;
echo $xml;
?>
Output :
<pd:answer>
<pd:text></pd:text>
</pd:answer><pd:answer>
<pd:text></pd:text>
</pd:answer><pd:answer>
<pd:text></pd:text>
</pd:answer>worldhello
Why the string are coming at the end of the output ?
Here is the link on codepad : http://codepad.org/2dbiCelb
Your function was echoing the xml code straight away. In the code below you will see I create a variable ($answer = "";) and then append the xml at the end of the variable by using ".=". At the end of the function I return the value of $answer.
When you call the function then ($ans = polldaddy_choices($total_choices);), it will place the return value of the function into your $ans variable.
<?php
function polldaddy_choices($choices) {
$answer = "";
foreach ($choices as $choice) {
$answer.= "<pd:answer>
<pd:text>" . $choice . "</pd:text>
</pd:answer>";
}
return $answer;
}
$total_choices = array('yes' , 'no' , 'do not know');
$ans = polldaddy_choices($total_choices);
$xml = "world" . $ans . "hello" ;
echo $xml;
?>
Your function is not retuning anything. You are echoing directly in that function.
So first you call polldaddy_choices, which echos the html. Then, you echo:
$xml = "world" . "" . "hello" ;
Because you are echoing the output in your polldaddy_choices function. So the following:
$ans = polldaddy_choices($total_choices); Is actually printing the XML, and:
$xml = "world" . $ans . "hello"; will simply be printing worldhello, as $ans === null
I think you probably want to be doing something more like:
function polldaddy_choices($choices) {
$answers = array();
foreach ($choices as $choice) {
$answer = "<pd:answer>
<pd:text>" . $choice . "</pd:text>
</pd:answer>";
$answers[] = $answer;
}
return implode("\n", $answers);
}