PHPã®éçºå¹çãä¸ããï¼ï¼åã®é¢æ°
ã追記とかãã«ã³ã¡ã³ãã®è¿çã追è¨ããã¦ã¾ãã®ã§åããã¦ã©ããã
ããããï¼å¹´ãããPHPããã£ã¦ããã®ã§ããã£ãããªã®ã§ï¼ï¼åã®ä¾¿å©ãªé¢æ°ã並ã¹ã¦ã¿ã¾ããã
ä½æ¥å¹çãããªãã¢ããããã®ã§ãããããPHPããã£ã¦ã¿ããããªãã£ã¦æãæ¹ã¯ç¥ã£ã¦ããã¨ä¾¿å©ã ã¨æãã¾ãã
å¤æ°ãé åã®å 容ããã¬ã¤ã«è¡¨ç¤ºããé¢æ°ãdã
å¤æ°ãé
åã®å
容ãHTMLæ§æã§ãã¬ã¤ã«è¡¨ç¤ºãã¦ããã¾ãã
ããããvar_dumpã¨æ¸ãã¨ã¿ã¤ãã³ã°ã大å¤ãªã®ã§ãd($hoge)ãã¨ãã¦ç°¡åã«è¨è¿°ã
ããã ãã§ãä½æ¥å¹ç8å
function d() { echo '<pre style="background:#fff;color:#333;border:1px solid #ccc;margin:2px;padding:4px;font-family:monospace;font-size:12px">'; foreach (func_get_args() as $v) var_dump($v); echo '</pre>'; }
ç°¡åã«htmlã®ã¨ã¹ã±ã¼ããsqlã®ã¨ã¹ã±ã¼ãããã¦ãããé¢æ°ãhã,ãeã
ç°¡åã«htmlã®ã¨ã¹ã±ã¼ããsqlã®ã¨ã¹ã±ã¼ãããã¦ãããé¢æ°ãhã,ãeãã
ãããé
åã«ã対å¿ãã¦ããã®ã§ãã¾ã¨ãã¦å¦çãã¦ããã¾ãã
htmlspecialcharsã¯ã¨ã¦ãé·ãé¢æ°åãªã®ã§ãhãã¨ãã¦å©ç¨ããã¨16åæ©ãæ¸ãã¾ã(ç¬)ã
$str_h = h( "<a>hoge</a>"); $str_e = e( "select * from hoge where 1 -- '' " ); function h($str){ if(is_array($str)){ return array_map( "h",$str ); }else{ return htmlspecialchars($str,ENT_QUOTES); } } function e($str){ if(is_array($str)){ return array_map( "e" , $str ); }else{ return mysql_real_escape_string( $str ); } }
ãã¡ã¤ã«ã®èªã¿æ¸ããããããï¼è¡ã§ã
ãã¡ã¤ã«ã®èªã¿æ¸ããããããï¼è¡ã§ã§ããé¢æ°ãfile_get_contentsã,ãfile_put_contentsãã
//èªã¿è¾¼ã¿ $file = file_get_contents( "http://yourfile/" ); $file .= "æå追å "; //æ¸ãåºã file_put_contents( "output.txt" , $file);
ï½è¨èªã§ããªãã¿ã®ãfopenãã¯ãfgetcsvããªã©csvãã¡ã¤ã«ãèªã¿è¾¼ãã¨ããç¹æ®ãªæã«ä½¿ãã¨ããããï¼
xmlãã¡ã¤ã«ãé åã«å¤æãã¦ãããã©ã¤ãã©ãªãXML/Unserializer.phpã
PHPã§å¤é¨ï¼¡ï¼°ï¼©ã使ç¨ããã¨ä½ãã¨XMLã®è§£æãå¤ãã®ã§ã©ã¤ãã©ãªã使ç¨ãã¦é
åã«å¤æã§ãã¾ãã
PEARã©ã¤ãã©ãªã®XML_Serializerãå¿
è¦
require_once 'XML/Unserializer.php'; $Unserializer =& new XML_Unserializer( array('parseAttributes' => true, 'targetEncoding' => 'utf-8' ) ); $file = file_get_contents( "http://hoge.xml" ); $status = $Unserializer->unserialize( $file); $xml = $Unserializer->getUnserializedData(); var_dump( $xml );
ã¡ãªã¿ã«simplexml_load_fileã§ãOKã
ã¡ãã£ã¨ã¯ã»ããããã©ã
$xml = simplexml_load_file( "http://hoge.xml" ); var_dump( $xml );
ãã¼ã ã¹ãã¼ã¹ã®åé¡ãé¢åãªå ´åã¯
$xml = file_get_contents( "http://hoge.xml" ); $xml = str_replace( ":" , "_" , $xml ); $xml_arr = simplexml_load_string( $xml );
ã¨ãã¦ãã¼ã ã¹ãã¼ã¹ãç¡å¹ã«ãã¦è§£æãã¾ãã
ãã ãããªãã¡ãã£ã¦è§£æãªã®ã§æ³¨æã
ã¡ã¼ã«éä¿¡ãï¼è¡ã§è¡ããmb_send_mailã
ã¡ã¼ã«éä¿¡ãï¼è¡ã§è¡ããmb_send_mailãé¢æ°ã
æ¥æ¬èªãã«ããã¤ãã«ã対å¿ãã¦ããã®ãç¹å¾´ã
mb_send_mail( "[email protected]" , "ã¿ã¤ãã«" , "å 容" , "From: [email protected]" );
ã¡ãªã¿ã«æ·»ä»ã¡ã¼ã«ã«ã¯å¯¾å¿ãã¦ããªãã®ã§ãèªåã§ä½ãã
HTMLã¡ã¼ã«ã«ã¯ç°¡åã«å¯¾å¿å¯è½ã
mb_send_mail( "[email protected]" , "ã¿ã¤ãã«" , "<html>å 容</html>" , "From: [email protected]\r\nContent-Type: text/html" );
æºå¸¯ã³ã³ãã³ãåãã«å ¨è§ã«ããåè§ã§è¡¨ç¤ºãmb_convert_kanaã
æºå¸¯çã®å ´åã¯åè§ã«ãã表示ããï¼°ï¼£çã®ã¨ãã¯å ¨è§ã«ãã表示ãããã¨ãç°¡åã«ã§ããã
$ZENKAKU = mb_convert_kana( "åè§ã«ãã«å¤æãããï¼" , "k" );
æåã³ã¼ããä¸æ¬ã§ã§ããmb_convert_encodingã便å©ã
//sjis -> utf-8 ã«å¤æ
$html = mb_convert_encoding($html, 'UTF-8', 'SJIS');
çµµæååé¤ã«ã使ãã
mb_substitute_character('none'); $html = mb_convert_encoding($html, 'SJIS', 'SJIS');
HTMLã¿ã°ãSQLæã§æ½åºãããhtmsqlã
HTMLã¿ã°ãSQLæã§æ½åºãããhtmsqlã
æ£è¦è¡¨ç¾ãåå¼·ããæããªããã§ãHTï¼ï¼¬ã解æãããæ¹åãã
htmlSQL
$wsql = new htmlsql(); $wsql->connect('string', $file); $wsql->query('SELECT * FROM div WHERE $class="header"'); foreach( $wsql->fetch_array() as $row ){ var_dump( $row ); }
ä½æãã緯度çµåº¦ã«å¤æãããaddress2gpsã
GoogleAPIãå©ç¨ãã¦ä½æã緯度çµåº¦ã«å¤æ
HTTP リクエスト経由のジオコーディング
$xml = address2gps( "æ±äº¬é½å代ç°åº" ); var_dump( $xml ); function address2gps( $address ){ $APIKEY = "Google API KEY"; $url = "http://maps.google.co.jp/maps/geo?key={$APIKEY}&q={$address}&output=xml&ie=UTF-8"; $file = file_get_contents( $url ); return $file; }
googlechart
ã°ã©ãä½æã
Google Charts APIをPHPから簡単に操作できるようにしたライブラリ『googChart』
jpgraphã§ãä½æå¯è½ã
URLãã¡ã¼ã«ã¢ãã¬ã¹ã®èªåãªã³ã¯ãconvert_linkã
æååã解æãã¦ãèªåã§URLãªã³ã¯ãã¡ã¼ã«ã¢ãã¬ã¹ã®ãªã³ã¯ããã¦ãããã
function convert_link( $val ){ //ã¿ã°ã®é¤å» $val = strip_tags( $val ); //èªåãªã³ã¯ $val = mbereg_replace("(https?|ftp|news)"."(://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+)","[<A href=\"\\1\\2\" target=\"_blank\">URL</A>]", $val); $val = mbereg_replace("([0-9A-Za-z\.\/\~\-\+\:\;\?\=\&\%\#\_]+@[-0-9A-Za-z\.\/\~\-\+\:\;\?\=\&\%\#\_]+)","[<A href=\"mailto:\\1\">MAIL</A>]", $val); //æ¹è¡ãbrã¿ã°ã«å¤æ $val = nl2br( $val ); return $val; }
以ä¸ã§ããPHPã©ã¯ã§ä¾¿å©ã ãªãã£ã¦æã£ã¦ããããããããã§ãã
PHPã«ã¯ä¾¿å©ãªã©ã¤ãã©ãªãé¢æ°ãããã®ã§ãã¾ãã¯ä½ãã§ãããã調ã¹ãä¸ã§ããã°ã©ã ãæ¸ãã¨ããããªãã£ã¦æãã¾ãã