public function escape($str) { if (version_compare(PHP_VERSION, '5.5.0') >= 0) { return curl_escape($this->ch, $str); } throw new Exception\FeatureUnavailableException('curl_escape() is not supported prior to PHP 5.5.0'); }
/** * Using spotify api to get spotify uri. * @param string $artist * @param string $albumName * @return string uri; * @throws \Exception */ public function getAlbumSpotifyURI($artist, $albumName) { $ch = curl_init(); if (!$ch) { throw new \CurlInitException(); } $url = "https://api.spotify.com/v1/search?q=album:" . curl_escape($ch, $albumName) . "+artist:" . curl_escape($ch, $artist) . "&type=album"; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); $result = json_decode($result); if (empty($result)) { curl_close($ch); throw new \WebServiceEmptyResultException(curl_error($ch)); } else { $info = curl_getinfo($ch); curl_close($ch); if ($info["http_code"] !== 200) { throw new \BadResponseCodeException(); } } $uri = $result->albums->items[0]->uri; return filter_var($uri, FILTER_SANITIZE_STRING); }
/** * @requires HHVM 999 * @requires PHP 5.5 */ public function stringsToEscape() { $ch = curl_init(); if (version_compare(PHP_VERSION, '5.5.0') >= 0 && !defined('HHVM_VERSION')) { return [[curl_escape($ch, 'Hofbräuhaus / München'), 'Hofbräuhaus / München'], [curl_escape($ch, 'http://example.com/add_location.php?location=Hofbräuhaus / München'), 'http://example.com/add_location.php?location=Hofbräuhaus / München']]; } // Unsupported in PHP <5.5 return [[]]; }
public function getBnfResponse() { $input = Input::get("input"); $curl = curl_init(); $inputF = curl_escape($curl, $input); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => "http://www.testtutor.com:8080/tutor/query?input=" . $inputF)); $resp = curl_exec($curl); curl_close($curl); //$json = file_get_contents("http://www.testtutor.com:8080/tutor/query?input=".$inputF) return Response::json(json_decode($resp)); }
/** * URL encodes the given string * * @author Art <*****@*****.**> * * @param string $str The string * * @return string The escaped string * @link http://php.net/manual/en/function.curl-escape.php */ function escape($str) { return curl_escape($this->ch, $str); }
<?php $str = "http://www.php.net/ ?!"; $a = curl_init(); $escaped = curl_escape($a, $str); $original = curl_unescape($a, $escaped); var_dump($escaped, $original); var_dump(curl_unescape($a, 'a%00b'));
public function getAddressCoordinate($address) { $address1 = $address['address1']; $address2 = $address['address2']; $postcode = $address['postcode']; $city = $address['city']; $curl = curl_init(); $location = curl_escape($curl, $address1 . ',' . $city); $req = "https://maps.googleapis.com/maps/api/geocode/json?address={$location}"; $curl = curl_init($req); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); return json_decode($result, true)['results'][0]['geometry']['location']; }
/** * Url-encode a string * * @param $string * @return bool|string */ public function encode($string) { return curl_escape($this->ch, $string); }
public function escape(string $str) : string { if (!is_resource($this->init)) { throw new InvalidArgumentException('Error', 'resourceParameter', '1.(ch)'); } return curl_escape($this->init, $str); }
function upload_check($str, $top, $left, $right, $bottom) { if ($str != null) { $ch = curl_init(); $fp = fopen("files/map.xml", "w"); $str = curl_escape($ch, $str); $str = "http://overpass-api.de/api/interpreter?data={$str}"; curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_URL, $str); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); //database $result = pg_query($GLOBALS['db_connection'], "truncate users,nodes,ways,way_nodes,relations,relation_members;"); //osmosis echo shell_exec('osmosis --read-xml "files/map.xml" --log-progress --write-pgsql database=osm user=postgres password=balaji07'); } $result = pg_query($GLOBALS['db_connection'], "truncate points,lines,polygons,lines_bon,polygons_bon;"); $result = pg_query($GLOBALS['db_connection'], "insert into polygons_bon (select * from polygons_all" . $GLOBALS['retail_bool'] . " where st_dwithin(ST_GeomFromText('POLYGON((" . $left . " " . $top . "," . $right . " " . $top . "," . $right . " " . $bottom . "," . $left . " " . $bottom . "," . $left . " " . $top . "))',4326)::geography,geom::geography,0)=true);"); $result = pg_query($GLOBALS['db_connection'], "insert into lines_bon (select * from lines_all" . $GLOBALS['retail_bool'] . " where st_dwithin(ST_GeomFromText('POLYGON((" . $left . " " . $top . "," . $right . " " . $top . "," . $right . " " . $bottom . "," . $left . " " . $bottom . "," . $left . " " . $top . "))',4326)::geography,geom::geography,0)=true);"); //database check and modify $result = pg_query($GLOBALS['db_connection'], "update nodes set tagsarr=fun(id);"); $result = pg_query($GLOBALS['db_connection'], "insert into polygons (select id,ST_MakePolygon(linestring) from ways where nodes[1]=nodes[array_upper(nodes,1)] and array_upper(nodes,1)>=4);"); $result = pg_query($GLOBALS['db_connection'], "insert into lines (select id,linestring from ways where nodes[1]!=nodes[array_upper(nodes,1)] or array_upper(nodes,1)<4);"); $result = pg_query($GLOBALS['db_connection'], "SELECT COUNT(*) FROM nodes;"); $nodes = pg_fetch_row($result); $nodes = intval($nodes[0]); if ($nodes == 0 && $str != null) { return "no_records"; } else { return "success"; } }
public function escape($str = '') { if (!isPhpVersion('5.5.0')) { die(getErrorMessage('Error', 'invalidVersion', array('%' => 'curl_escape', '#' => '5.5.0'))); } if (!is_resource($this->init)) { return Error::set('Error', 'resourceParameter', '1.(ch)'); } return curl_escape($this->init, $str); }
function config_omit_features($top, $bottom, $left, $right) { $add_places = $GLOBALS['add_places']; $ret = $GLOBALS['ret']; $str = "("; ///adding omiting features foreach ($add_places as $place) { $s = ""; foreach ($place as $p) { $s = $s . '[' . $p . ']'; } $str = $str . 'way' . $s . '(' . $bottom . ',' . $left . ',' . $top . ',' . $right . ');'; $str = $str . 'rel' . $s . '(' . $bottom . ',' . $left . ',' . $top . ',' . $right . ');'; } $str = $str . ');(._;>;);out meta;'; $file = fopen("files/log2.txt", "w"); fwrite($file, $str); fclose($file); $ch = curl_init(); $fp = fopen("files/mapomit.xml", "w"); $str = curl_escape($ch, $str); $str = "http://overpass-api.de/api/interpreter?data={$str}"; curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_URL, $str); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); //database $result = pg_query($GLOBALS['db_connection'], "truncate users,nodes,ways,way_nodes,relations,relation_members,lines_all" . $ret . ",polygons_all" . $ret . ";"); //osmosis echo shell_exec('osmosis --read-xml "files/mapomit.xml" --log-progress --write-pgsql database=osm user=postgres password=balaji07'); //database check and modify //$result = pg_query($GLOBALS['db_connection'],"update nodes set tagsarr=fun(id);") ; $result = pg_query($GLOBALS['db_connection'], "insert into polygons_all" . $ret . " (select id,ST_MakePolygon(linestring) from ways where nodes[1]=nodes[array_upper(nodes,1)] and array_upper(nodes,1)>=4);"); $result = pg_query($GLOBALS['db_connection'], "insert into lines_all" . $ret . " (select id,linestring from ways where nodes[1]!=nodes[array_upper(nodes,1)] or array_upper(nodes,1)<4);"); //$result = pg_query($GLOBALS['db_connection'],"truncate users,nodes,ways,way_nodes,relations,relation_members") ; }
/** * @param string $string * @return bool|string */ public function escape($string) { return curl_escape($this->handle, $string); }
/** * URL encodes the given string * * @see http://php.net/manual/en/function.curl-escape.php * * @param $string * * @return string * @throws \Exception */ public function escape($string) { $return = curl_escape($this->handle, $string); if ($return === false) { throw new \Exception('An error occurred'); } return $return; }
/** * @param string $str * * @return bool|string */ public function escape($str) { return function_exists('curl_escape') ? curl_escape($this->_curl_handle, $str) : $str; }
/** * URL encodes the given string * * @param string $str The string to be encoded. * @return string Escaped string */ public final function curlEscape($str) { return curl_escape($this->curl_handle, $str); }
/** * URL encodes the given string * @param $escapestring * @return bool|string */ private function curlEscape($escapestring) { return curl_escape($this->curl, $escapestring); }
/** * Encode string according to RFC3986 * @param $String String * @return String */ public function escape($String) { return curl_escape($this->Curl, $String); }
/** * URL encodes the given string * @see http://php.net/manual/en/function.curl-escape.php Official PHP documentation for curl_escape() * @param string $str The string to be encoded * @return string|boolean Returns escaped string or **FALSE** on failiure */ public function escape($str) { return curl_escape($this->_ch, $str); }
说明 string curl_escape ( resource $ch , string $str ) 该函数使用 URL 根据? RFC 3986编码给定的字符串。 参数 ch 由 curl_init() 返回的 cURL 句柄。 str 需要编码的字符串 返回值 返回编码后的字符串 或者在失败时返回 FALSE。 */ // 创建一个 curl 句柄 $ch = curl_init(); // 把编码后的字符串当做一个 GET 参数 $location = curl_escape($ch, 'Hofbr?uhaus / München'); // 结果: Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen // 用编码好的字符串组装一个 URL $url = "http://example.com/add_location.php?location={$location}"; // 结果: http://example.com/add_location.php?location=Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen // 发送 HTTP 请求并关闭句柄 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); curl_close($ch);