$to= array();
foreach($users as $v) {
$to[(string)$v['address']] = (float)($v['amount']*100000);
}
$guid = "user";
$main_password = "pw";
$second_password = "pw2";
$fee = 60000;
$recipients = urlencode(json_encode($to));
$from = "address";
$note = "public";
$json_url = "https://blockchain.info/merchant/$guid/sendmany?password=".$main_password."&second_password=".$second_password."&recipients=".$recipients."&shared=false&fee=".$fee."¬e=".$note."&from=".$from;
echo $json_url;
die();
For some reason, when I echo $json_url;, the ¬e= is transformed to ¬e=. I can't find any PHP or HTML symbol that could be making that transformation.
That is ¬, or ¬ (mathematical not). Always use & to echo out an ampersand (even in URLs) if you're using HTML. Browsers are tolerant of sloppy coding, but in this case it can bite you.
Related
I am using SimplePie library for feed generation. I made some changes for desired output. It was working great till today.
Here is my code:
<?php
header('Content-type: text/plain; charset=utf-8');
// Include the SimplePie library
// For 1.0-1.2:
#require_once('simplepie.inc');
// For 1.3+:
require_once('autoloader.php');
// Create a new SimplePie object
$feed = new SimplePie();
// Instead of only passing in one feed url, we'll pass in an array of three
$feed->set_feed_url(array(
'http://localhost/full-text-rss/makefulltextfeed.php?url=dynamic.feedsportal.com%2Fpf%2F555218%2Fhttp%3A%2F%2Ftoi.timesofindia.indiatimes.com%2Frssfeedstopstories.cms&key=1&hash=759dbac5d2121d4b7bc31ee9119d65a44a73fb6d&max=10&links=preserve&exc=1&format=json'
));
//Caching is enabled
$feed->enable_cache(true);
//timeout
$feed->set_timeout(40);
// We'll use favicon caching here (Optional)
//$feed->set_favicon_handler('handler_image.php');
// Initialize the feed object
$feed->init();
// This will work if all of the feeds accept the same settings.
$feed->handle_content_type();
if ($feed->error)
{
echo $feed->error;
}
$newspaperName = array('Google News');
$i = 0;
$j = 0;
$response = array();
$response["NewsItems"] = array();
foreach ($feed->get_items() as $item)
{
$feed = $item->get_feed();
//$permalink =
//$NewsItems["Count"] = html_entity_decode($feed,ENT_QUOTES, "UTF-8");//html_entity_decode($item->get_id(),ENT_QUOTES, "UTF-8");
$NewsItems["ArticleLink"] = html_entity_decode($item->get_permalink(),ENT_QUOTES, "UTF-8");//$permalink;
$NewsItems["Title"] = html_entity_decode($item->get_title(), ENT_XHTML, "UTF-8");
$NewsItems["Content"]= html_entity_decode($item->get_content(), ENT_XHTML, "UTF-8");
if($i==10)
{
$i = 0;
$NewsItems["Source"] = html_entity_decode($newspaperName[$j+1],ENT_QUOTES, "UTF-8");
$j++;
}
else
{
$NewsItems["Source"] = html_entity_decode($newspaperName[$j],ENT_QUOTES, "UTF-8");;
$i++;
}
$feed = $item->get_feed();
$NewsItems["SourceLink"]= html_entity_decode($feed->get_permalink(), ENT_XHTML, "UTF-8");
$feed = $item->get_feed();
$NewsItems["SourceTitle"] = html_entity_decode($feed->get_title(), ENT_XHTML, "UTF-8");
$NewsItems["Date"]= html_entity_decode($item->get_date('j M Y | g:i a T'), ENT_XHTML, "UTF-8");
array_push($response["NewsItems"], $NewsItems);
}
echo json_encode($response);
?>
But Today suddenly I got an error:
Notice: Array to string conversion in C:\xampp\htdocs\simplepie\IndiaEnglishTopStories.php on line 38
Array{"NewsItems":[]}
Line 38 is:
echo $feed->error;
I am not a php developer so my knowledge is very much limited. I read so many answer here and I tried to implement that but still problem is there. Forgive me if you find this question stupid and annoying. Thank you for your time.
Your trying to echo a array this is not possible. $feed->error is an array.
Change to
foreach($feed->error as $err)
echo $err;
or
var_dump($feed->error)
or
print_r($feed->error)
How to echo or print an array in PHP?
This is really annoying me, the php script was working and returning the weather from open weather map but literally all of a sudden the php script takes forever to execute and the following error is produced:
Warning: file_get_contents(http://api.openweathermap.org/data/2.5/weather?lat=&lon=&units=metric&cnt=7&lang=en&key=f38a36af9e4965dd5192ba4282abe070) [function.file-get-contents]: failed to open stream: Connection timed out in /xxx/xxx/public_html/fullweather.php on line 15
Any help would be appreciated. The php script can be viewed below. Only the beginning is important (first 18 lines) but I have included the full thing.
<?php
$lat = $_POST["latitude"];
$lon = $_POST["longitude"];
$url="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&units=metric&cnt=7&lang=en&key=f38a36af9e4965dd5192ba4282abe070";
// Make call with cURL
$session = curl_init($url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
$json=file_get_contents($url);
$data=json_decode($json,true);
class weatherdata
{
public $temp = "";
public $weather = "";
public $clouds = "";
public $area = "";
public $humidity = "";
public $humidpressure = "";
public $weatherdesc = "";
public $tempmin = "";
public $tempmax = "";
public $windspeed = "";
public $winddirec = "";
}
$data1 = $data['main']['temp'];
$data2 = $data['weather'][0]['main'];
$data3 = $data['clouds']['all'];
$data4 = $data['name'];
$data5 = $data['main']['humidity'];
$data6 = $data['main']['pressure'];
$data7 = $data['weather'][0]['description'];
$data8 = $data['main']['temp_min'];
$data9 = $data['main']['temp_max'];
$data10 = $data['wind']['speed'];
$data12 = $data['wind']['deg'];
$weatherdata = new weatherdata();
$weatherdata->temp = $data1;
$weatherdata->weather = $data2;
$weatherdata->clouds = $data3;
$weatherdata->area = $data4;
$weatherdata->humidity = $data5;
$weatherdata->humidpressure = $data6;
$weatherdata->weatherdesc = $data7;
$weatherdata->tempmin = $data8;
$weatherdata->tempmax = $data9;
$weatherdata->windspeed = $data10;
$weatherdata->winddirec = $data12;
$output[] = $weatherdata;
print(json_encode($output));
?>
I think the API was just down, cause the link is working for me right now.
Try one more time.
May be the API had change it's url by the time. Try to check the documentation for any updated information. I think that they could change it and your code couldnt find because this $url doesn't exist anymore.
i added https instead of http in url and it worked.
so maybe change http in url like this url.
$url="https://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&units=metric&cnt=7&lang=en&key=f38a36af9e4965dd5192ba4282abe070";
Edit
Also you should not show your api key to anyone as some one can use it.
I'm trying to add some keywords in AdWords using PHP language and AdWords API. When I add keywords in english it works fine, but in russian it shows me next error message:
[SoapFault]
SOAP-ERROR: Encoding: string '\xd2...' is not a valid utf-8 string (0)
/var/www/html/www3.repka.com.ua/sources/repka/work/adwords/AdWordsApi/source/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php:232
#0: SoapClient->__soapCall(string, array, NULL, array, array)
/var/www/html/www3.repka.com.ua/sources/repka/work/adwords/AdWordsApi/source/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php:232
#1: AdsSoapClient->__soapCall(string, array)
/var/www/html/www3.repka.com.ua/sources/repka/work/adwords/AdWordsApi/source/src/Google/Api/Ads/AdWords/v201409/AdGroupCriterionService.php:9936
#2: AdGroupCriterionService->mutate(array)
/var/www/html/www3.repka.com.ua/sources/repka/work/adwords/index.php:213
Bellow You can see my code:
$adGroupId = 1648319****;
$adGroupId = (float)$adGroupId;
$user = new AdWordsUser();
$user->LogAll();
$word = "Текст"; // error, but with $word = "Keyword" it works fine
echo $word;
echo urlencode($word);
$word = urlencode($word);
$adGroupCriterionService = $user->GetService('AdGroupCriterionService', 'v201409');
// Create keyword criterion.
$keyword = new Keyword();
$keyword->text = $word;
$keyword->matchType = 'BROAD';
// Create biddable ad group criterion.
$adGroupCriterion = new BiddableAdGroupCriterion();
$adGroupCriterion->adGroupId = $adGroupId;
$adGroupCriterion->criterion = $keyword;
// Set additional settings (optional).
$adGroupCriterion->userStatus = 'PAUSED';
$adGroupCriterion->destinationUrl = 'https://repka.ua/noutbuki/asus-s301lp-s301lp-c1010h-92202/';
$adGroupCriteria[] = $adGroupCriterion;
//var_dump($adGroupCriteria);
// Create operation.
$operation = new AdGroupCriterionOperation();
$operation->operand = $adGroupCriterion;
$operation->operator = 'ADD';
$operations[] = $operation;
$result = $adGroupCriterionService->mutate($operations);
// Display results.
foreach ($result->value as $adGroupCriterion) {
printf("Keyword with text '%s', match type '%s', and ID '%s' was added.\n",
$adGroupCriterion->criterion->text,
$adGroupCriterion->criterion->matchType,
$adGroupCriterion->criterion->id);
}
Tell me please how can I solve this problem?
Thanks!
It looks like the API only accepts UTF-8 strings. So you will need to convert that russian text to be a UTF-8 encoded string.
mb_detect_encoding can help you figure out what the existing encoding is and iconv will allow you to convert it to UTF-8.
Try this:
$word = "Текст";
$word = iconv(mb_detect_encoding($word, mb_detect_order(), true), "UTF-8", $word);
i want to use PHP for internet service in my IOS 7 application.
I've tried to generate an code for receiving objects from a Firebird database.
My Code bellow:
<?php
$host = 'xxx';
$username = 'xxx';
$password = 'xxx';
$conn = ibase_connect($host, $username, $password) or
die ("Verbindung fehlgeschlagen");
$arr = array();
$data = array();
$stmt = "select * from xxx";
$sth = ibase_query($conn, $stmt);
while ($row = ibase_fetch_object ($sth)) {
$data['ID'] = $row->ID;
$data['VON'] = $row->VON;
$data['AN'] = $row->AN;
$data['BETREFF'] = $row->BETREFF;
$data['DATUM'] = $row->DATUM;
$data['KOMMISSIONSNR'] = $row->KOMMISSIONSNR;
$data['NACHRICHT'] = $row->NACHRICHT;
$data['GELESEN'] = $row->GELESEN;
$data['GEANTWORTET'] = $row->GEANTWORTET;
$data['STATUS'] = $row->STATUS;
$data['AUFTRAG'] = $row->AUFTRAG;
$arr[] = array($data);
}
echo json_encode($arr);
?>
By calling the code in Safari-browser no values or arrays be returned.
If giving an Key like 1
(echo json_encode($arr[1]);) an array on the browser will be shown.
How can i show the whole array with all keys? I should add that i want to use the results from my ibase-query as NSDictionary in the application.
And which framework is the best for encoding the PHP-Array to IOS? I've tried to use JSONDictionaryExtensions, but don't know if it's the right for this Code.
i hope you can help me.
Sorry for my bad english.
I'm not sure why you are putting the $data array into another array. You can skip that step.
When you echo json_encode($data) you encode the array as JSON, so that is what your iOS application gets and what it needs to decode. Decoding JSON into an NSArray or NSDictionary has been asked many times here on StackOverflow, like this question.
I am using html_entity_decode($string) to decode html special characters such as ä=ä. I am then using json_encode() to create a json string that I use for an Android application. My problem is that i get an output of \u00e4 instead of 'ä'. I know that json_encode() only works with UTF-8 encoded strings, but when I run mb_detect_encding($myString) on my values it returns "UTF-8". It does't help to run ut8_encode() on the values. Here is my code:
$newsList = array();
while($row = $news->fetch_object()){
$tmpNews = new News();
$tmpNews->imgId = $row->image_id;
$tmpNews->author = html_entity_decode($row->author);
$tmpNews->subject = $row->subject;
$tmpNews->msg = $row->msg;
$tmpNews->newsmsg = $row->newsmsg;
$tmpNews->date = $row->wdate;
array_push($newsList, $tmpNews);
$tmpNews = null;
}
$json = array();
foreach($newsList as $news){
array_push($json, $news->getJson());
}
var_dump($json);
echo json_encode($json);
When i do the var_dump($json) my special characters shows as normal.