I need one help. I need to fetch all data from query string using PHP but some special charcters like (i.e-+,- etc) are not coming. I am explaining my code below.
http://localhost/test/getmethod.php?name=Goro + Gun
Here I need to get the value assign to name using the below code.
<?php
$name=$_GET['name'];
echo $name;
?>
Here I am getting the output like Goro Gun but I need the original value i.e-Goro + Gun .Please help me to resolve this issue.
#subhra try this for this case name=Goro + Gun:
<?php
$nameArr = explode('=', $_SERVER['QUERY_STRING']);
$name = str_replace("%20", " ", $nameArr[1]);
echo $name;
?>
$_SERVER['QUERY_STRING'] - this will return you full query string
Related
i am trying to use echo inside url. i have store data from the form in database and now i am also fetching it on my page and its working well. Now i am trying to print that data i.e. number and date in url.
Is it possible and if possible please help me out
here is my data that i am fetching and it prints the output
echo $number;
echo $yyyymmdd;
and here is my url in which i want to insert ' echo $number; ' and ' echo $yyyymmdd; ' on the place of and .
$json= file_get_contents("http://api.com/api/a2/live/apikey/fc5a69f870fdb03/number/<number>/date/<yyyymmdd>/");
I have also tried something like this but it gives error of syntex error.
$json= file_get_contents("http://api.com/api/a2/live/apikey/fc5a69f870fdb03/number/"echo $number;"/date/"echo $yyyymmdd;"/");
Another way to add changing parameters to a URL (or string) is by using sprintf(). You define your URL and a type specifier like %d as a placeholder for numbers, and %s for strings. See the php doc for the full list of type specifiers.
$urlFormat = "http://api.com/api/a2/live/apikey/fc5a69f870fdb03/number/%d/date/%s/"
^ ^
Then call sprintf with the changing parameters in order of appearance.
$url = sprintf($urlFormat, $number, $yyyymmdd);
$json = file_get_contents($url);
This becomes more convenient especially if you are calling file get contents in a loop.
Create two variables and append those two inside double-quote or single quote, depending upon the quotes which you have opened and close it.
<?php
$number=123;
$yyyymmdd='2018-10-9';
$json= file_get_contents("http://api.com/api/a2/live/apikey/fc5a69f870fdb03/".$number."/<number>/date/<".$yyyymmdd.">/");
?>
$json= file_get_contents("http://api.com/api/a2/live/apikey/fc5a69f870fdb03/number/".$number."/date/".$yyyymmdd."/");
When you compose text, you do not need "echo" but just can write variable.
You can directly use variables in double quotes like this
file_get_contents("http://api.com/api/a2/live/apikey/fc5a69f870fdb03/number/$number/date/$yyyymmdd/");
Sample code below
$number = 344;
$yyyymmdd = "20180301";
$url1 = "http://api.com/api/a2/live/apikey/fc5a69f870fdb03/number/$number/date/$yyyymmdd/";
echo "url1 ".$url1."\n";
$url2 = "http://api.com/api/a2/live/apikey/fc5a69f870fdb03/number/".$number."/date/".$yyyymmdd."/";
echo "url2 ".$url2. "\n";
I'm working on a project that uses the Facebook API. Im using methods from that API to automaticly create a username. But for that I need to add the firstname and the lastname.
The way on how I retrieve the firstname and lastnames is:
$userNode->getLastName();
$userNode->getFirstName();
How do I add those return values togheter?
If I do this:
$string = $userNode->getFirstName() + $userNode->getLastName();
echo "$string";
the echo shows "0".
Thanks in advance!
Mats de Waard
The first string operators example in the manual will show you:
$string = $userNode->getFirstName() . $userNode->getLastName();
You need to make a concatenation in php
in your example use "." instead of "+"
$string = $userNode->getFirstName() . $userNode->getLastName();
I have the following code which gets the URL parameter after the ? and displays it.
<?php
$qt = http_build_query($_GET);
echo $qt;
?>
But the problem i am having is that, whenever the URL is as follows:
http://example.net/blog?123
The output is as follows:
123=
How can i get rid of that "=" sign? I am parsing this into a mysql db, so the equal sign is not necessary.
Thank you!
P.S: I know that i need to sanitize the requests for security reasons, and i have that covered.
Use str_replace:
$qt = str_replace("=", "", http_build_query($_GET));
Just try this:
str_replace("=", "", $qt);
How can I have text within a php variable be bold??
function show_balance_header ($balance, $currency)
{
(string)$display_output = null;
$display_output = fees_main::display_amount(abs($balance), $currency, true);
return $display_output;
}
I want to bold $balance. Is there an easy way or do I need to edit display_amount?
I've tried doing this:
"<b>".$balance"</b>" but this did not get the correct variable,
thanks in advance!!
Needs to be "<b>" . $balance . "</b>". Concatenate <b> to $balance and concatenate again to </b>
Edit:
Assuming this does the printing/formatting: fees_main::display_amount(abs($balance)
You want fees_main::display_amount('<b>' . abs($balance) . '</b>', $currency, true).
abs($balance) gets the absolute value as a number, and the concatenation (explained above) automatically casts them to strings. The rest of the parameters are passed the same way (unmodified, unbolded).
(string)$display_output = null; is unnecessary
On your element html, example:
<p> text <?php echo "<b>{$balance}</b>"; ?> text</p>
answer is to edit the inner function display_amount using Raeki's suggestion, for future questions, i think you must edit the inner-most function as only editing function show_balance_header did not get the correct variable
I know this may sound similar to some past Q/As, I think mine is slightly different though.. I have a webpage which I want to dynamically load text file information. I upload the text file through an iframe and I want to save this information from php to Javascript. Whenever I try to save this as a regular variable it doesn't work so I have tried to do this by saving this information as a part of the $_POST array under a hidden form named $_POST['hidden_form']. Whenever I try to read the php into Javascript, I keep getting an error "Unexpected token ILLEGAL." I have tried the following two codes:
for($i=0;$i< count($_POST['hidden_form']) ;$i++)
{
echo "saved_form[$i]='" . $_POST['hidden_form'][$i]. "';\n";
}
and
saved_form = <?php echo json_encode($_POST['hidden_form']); ?>;
Assigning a php array into a javascript array
I think the error has to do with the " ' " needed to specify the array but not sure. I have no idea where to go from here so any help would be GREATLY appreciated. If there are better methods to do this please let me know. Thanks in advance!
saved_form = '<?php echo addslashes(json_encode($_POST['hidden_form'])); ?>';
Or
for($i=0;$i< count($_POST['hidden_form']) ;$i++)
{
echo "saved_form[$i]='" . addslashes($_POST['hidden_form'][$i]) . "';\n";
}
Both should work, probably had quotes breaking something?
the best way i have used is,
text/javascript
var saved_form = <?php echo json_encode($_POST['hidden_form']) ?>
Please note there are no Quotes around the php so your saved_form is an Object not a string json string witch would require you to to use var form_object = eval(saved_form)
#Lee might have meant this?
Just a note though i would not use the Raw $_POST pass it to a function that can loop though and addSlashes every value inside the post some thing like
<?php
function arr_addSlashes($array){
$ret = array();
foreach($array as $k => $v){
$ret[$k] = addSlashes($v);
}
return $ret;
}
?>