本文整理汇总了PHP中p2h函数的典型用法代码示例。如果您正苦于以下问题:PHP p2h函数的具体用法?PHP p2h怎么用?PHP p2h使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了p2h函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $html
* @param array $fallbackEncodings
* @throws P2Exception
*/
public function __construct($html, array $fallbackEncodings = null)
{
set_error_handler(array($this, 'checkConversionFailure'), E_WARNING);
try {
$this->_conversionFailed = false;
$document = new DOMDocument();
$document->loadHTML($html);
// 代替エンコーディングを指定して再読み込み
if ($this->_conversionFailed && $fallbackEncodings) {
$orig_html = $html;
foreach ($fallbackEncodings as $charset) {
// <head>直後に<meta>を埋め込む
$charset = p2h($charset);
$html = str_replace('<rep2:charset>', "<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$charset}\">", preg_replace('/<head[^<>]*>/i', '$0<rep2:charset>', $orig_html));
$this->_conversionFailed = false;
$document = new DOMDocument();
$document->loadHTML($html);
if (!$this->_conversionFailed) {
break;
}
}
}
} catch (Exception $e) {
restore_error_handler();
throw new P2Exception('Failed to create DOM: ' . get_class($e) . ': ' . $e->getMessage());
}
restore_error_handler();
if ($this->_conversionFailed) {
throw new P2Exception('Failed to load HTML');
}
$this->_document = $document;
$this->_xpath = new DOMXPath($document);
}
示例2: wordForMatch
/**
* フォームから送られてきたワードをマッチ関数に適合させる
*
* @return string $word_fm 適合パターン。SJISで返す。
*/
public static function wordForMatch($word, $method = 'regex')
{
$word_fm = $word;
// 「そのまま」でなければ、全角空白を半角空白に矯正
if ($method != 'just') {
$word_fm = mb_convert_kana($word_fm, 's');
}
$word_fm = p2h(trim($word_fm));
if (in_array($method, array('and', 'or', 'just'))) {
// preg_quote()で2バイト目が0x5B("[")の"ー"なども変換されてしまうので
// UTF-8にしてから正規表現の特殊文字をエスケープ
$word_fm = mb_convert_encoding($word_fm, 'UTF-8', 'CP932');
if (P2_MBREGEX_AVAILABLE == 1) {
$word_fm = preg_quote($word_fm);
} else {
$word_fm = preg_quote($word_fm, '/');
}
$word_fm = mb_convert_encoding($word_fm, 'CP932', 'UTF-8');
// 他、regex(正規表現)なら
} else {
if (P2_MBREGEX_AVAILABLE == 0) {
$word_fm = str_replace('/', '\\/', $word_fm);
}
}
return $word_fm;
}
示例3: editFile
/**
* ファイル内容を読み込んで編集する関数
*/
function editFile($path, $encode, $title)
{
global $_conf, $modori_url, $rows, $cols, $csrfid;
if ($path == '') {
p2die('path が指定されていません');
}
$filename = basename($path);
$ptitle = 'Edit: ' . p2h($title) . ' (' . $filename . ')';
//ファイル内容読み込み
FileCtl::make_datafile($path) or p2die("cannot make file. ({$path})");
$cont = file_get_contents($path);
if ($encode == "EUC-JP") {
$cont = mb_convert_encoding($cont, 'CP932', 'CP51932');
}
$cont_area = p2h($cont);
if ($modori_url) {
$modori_url_ht = "<p><a href=\"{$modori_url}\">Back</a></p>\n";
} else {
$modori_url_ht = '';
}
$rows_at = $rows > 0 ? sprintf(' rows="%d"', $rows) : '';
$cols_at = $cols > 0 ? sprintf(' cols="%d"', $cols) : '';
// プリント
echo $_conf['doctype'];
echo <<<EOHEADER
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
{$_conf['extra_headers_ht']}
<title>{$ptitle}</title>
</head>
<body onload="top.document.title=self.document.title;">
EOHEADER;
$info_msg_ht = P2Util::getInfoHtml();
echo $modori_url_ht;
echo $ptitle;
echo <<<EOFORM
<form action="{$_SERVER['SCRIPT_NAME']}" method="post" accept-charset="{$_conf['accept_charset']}">
<input type="hidden" name="file" value="{$filename}">
<input type="hidden" name="modori_url" value="{$modori_url}">
<input type="hidden" name="encode" value="{$encode}">
<input type="hidden" name="rows" value="{$rows}">
<input type="hidden" name="cols" value="{$cols}">
<input type="hidden" name="csrfid" value="{$csrfid}">
<input type="submit" name="submit" value="Save">
{$info_msg_ht}<br>
<textarea style="font-size:9pt;" id="filecont" name="filecont" wrap="off"{$rows_at}{$cols_at}>{$cont_area}</textarea>
{$_conf['detect_hint_input_ht']}{$_conf['k_input_ht']}
</form>
EOFORM;
echo '</body></html>';
return true;
}
示例4: fetchSubjectTxt
/**
* subject.txtの並列ダウンロードを実行する
*
* @param string $mode
* @param array $_conf
* @return bool
*/
public static function fetchSubjectTxt($mode, array $_conf)
{
// コマンド生成
$args = array(escapeshellarg($_conf['expack.php_cli_path']));
if ($_conf['expack.dl_pecl_http']) {
$args[] = '-d';
$args[] = 'extension=' . escapeshellarg('http.' . PHP_SHLIB_SUFFIX);
}
$args[] = escapeshellarg(P2_SCRIPT_DIR . DIRECTORY_SEPARATOR . 'fetch-subject-txt.php');
switch ($mode) {
case 'fav':
case 'recent':
case 'res_hist':
case 'merge_favita':
$args[] = sprintf('--mode=%s', $mode);
break;
default:
return false;
}
if ($_conf['expack.misc.multi_favs']) {
switch ($mode) {
case 'fav':
$args[] = sprintf('--set=%d', $_conf['m_favlist_set']);
break;
case 'merge_favita':
$args[] = sprintf('--set=%d', $_conf['m_favita_set']);
break;
}
}
// 標準エラー出力を標準出力にリダイレクト
$args[] = '2>&1';
$command = implode(' ', $args);
//P2Util::pushInfoHtml('<p>' . p2h($command) . '</p>');
// 実行
$pipe = popen($command, 'r');
if (!is_resource($pipe)) {
p2die('コマンドを実行できませんでした。', $command);
}
$output = '';
while (!feof($pipe)) {
$output .= fgets($pipe);
}
$status = pclose($pipe);
if ($status != 0) {
P2Util::pushInfoHtml(sprintf('<p>%s(): ERROR(%d)</p>', __METHOD__, $status));
}
if ($output !== '') {
if ($status == 2) {
P2Util::pushInfoHtml($output);
} else {
P2Util::pushInfoHtml('<p>' . nl2br(p2h($output)) . '</p>');
}
}
return $status == 0;
}
示例5: setFavItaByRequest
/**
* リクエストパラメータからお気に板をセットする
*
* @param void
* @return bool
*/
function setFavItaByRequest()
{
global $_conf;
$setfavita = null;
$host = null;
$bbs = null;
$itaj = null;
$list = null;
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (isset($_GET['setfavita'])) {
$setfavita = $_GET['setfavita'];
}
if (isset($_GET['host'])) {
$host = $_GET['host'];
}
if (isset($_GET['bbs'])) {
$bbs = $_GET['bbs'];
}
if (isset($_GET['itaj_en'])) {
$itaj = UrlSafeBase64::decode($_GET['itaj_en']);
}
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['setfavita'])) {
$setfavita = $_POST['setfavita'];
}
if (isset($_POST['itaj'])) {
$itaj = $_POST['itaj'];
}
if (isset($_POST['url'])) {
if (preg_match("/http:\\/\\/(.+)\\/([^\\/]+)\\/([^\\/]+\\.html?)?/", $_POST['url'], $matches)) {
$host = $matches[1];
$host = preg_replace('{/test/read\\.cgi$}', '', $host);
$bbs = $matches[2];
} else {
$url_ht = p2h($_POST['url']);
P2Util::pushInfoHtml("<p>p2 info: 「{$url_ht}」は板のURLとして無効です。</p>");
}
} elseif (!empty($_POST['submit_setfavita']) && $_POST['list']) {
$list = $_POST['list'];
}
}
if ($host && $bbs) {
return setFavItaByHostBbs($host, $bbs, $setfavita, $itaj);
} elseif ($list) {
return setFavItaByList($list);
} else {
P2Util::pushInfoHtml("<p>p2 info: 板の指定が変です</p>");
return false;
}
}
示例6: fixed_name_get_select_element
/**
* 定型文を選択するselect要素を取得する
*
* @param string $name select要素のid属性値・兼・name属性値 (デフォルトは'fixed_message')
* @param string $onchange option要素が選択されたときのイベントハンドラ (デフォルトはなし)
* @return string select要素のHTML
*/
function fixed_name_get_select_element($name = 'fixed_message', $onchange = null)
{
$name_ht = p2h($name);
if ($onchange !== null) {
$onchange_ht = p2h($onchange);
$select = "<select id=\"{$name_ht}\" name=\"{$name_ht}\" onchange=\"{$onchange_ht}\">\n";
} else {
$select = "<select id=\"{$name_ht}\" name=\"{$name_ht}\">\n";
}
$select .= "<option value=\"\">定型文</option>\n";
foreach (fixed_message_get_persister()->getKeys() as $key) {
$key_ht = p2h($onchange);
$select .= "<option value=\"{$key_ht}\">{$key_ht}</option>\n";
}
$select .= "</option>";
return $select;
}
示例7: viewTxtFile
/**
* ファイル内容を読み込んで表示する関数
*/
function viewTxtFile($file, $encode)
{
if (!$file) {
p2die('file が指定されていません');
}
$filename = basename($file);
$ptitle = $filename;
//ファイル内容読み込み
$cont = FileCtl::file_read_contents(P2_BASE_DIR . DIRECTORY_SEPARATOR . $file);
if ($cont === false) {
$cont_area = '';
} else {
if (strcasecmp($encode, 'EUC-JP') === 0) {
$cont = mb_convert_encoding($cont, 'CP932', 'CP51932');
} elseif (strcasecmp($encode, 'UTF-8') === 0) {
$cont = mb_convert_encoding($cont, 'CP932', 'UTF-8');
}
$cont_area = p2h($cont);
}
// プリント
echo <<<EOHEADER
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
{$_conf['extra_headers_ht']}
<title>{$ptitle}</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
</head>
<body onload="top.document.title=self.document.title;">
EOHEADER;
P2Util::printInfoHtml();
echo "<pre>";
echo $cont_area;
echo "</pre>";
echo '</body></html>';
return true;
}
示例8: rss_get_save_path
/**
* RSSのURLからローカルに保存するファイルのパスを設定する
*/
function rss_get_save_path($remotefile)
{
global $_conf;
static $finished = array();
$remotefile = preg_replace('|^feed://|', 'http://', $remotefile);
if (array_key_exists($remotefile, $finished)) {
return $finished[$remotefile];
}
$pURL = @parse_url($remotefile);
if (!$pURL || !isset($pURL['scheme']) || $pURL['scheme'] != 'http' || !isset($pURL['host'])) {
$errmsg = 'p2 error: 不正なRSSのURL (' . p2h($remotefile) . ')';
$error = PEAR::raiseError($errmsg);
return $finished[$remotefile] = $error;
}
$localname = '';
if (isset($pURL['path']) && $pURL['path'] !== '') {
$localname .= preg_replace('/[^\\w.]/', '_', substr($pURL['path'], 1));
}
if (isset($pURL['query']) && $pURL['query'] !== '') {
$localname .= '_' . preg_replace('/[^\\w.%]/', '_', $pURL['query']) . '.rdf';
}
// 拡張子.cgiや.php等で保存するのを防ぐ
if (!preg_match('/\\.(rdf|rss|xml)$/i', $localname)) {
// 古いバージョンで取得したRSSを削除
if (file_exists($localname)) {
@unlink($localname);
}
// 拡張子.rdfを付加
$localname .= '.rdf';
}
// dotFileが作られるのを防ぐ
if (substr($localname, 0, 1) == '.') {
$localname = '_' . $localname;
}
$localpath = $_conf['dat_dir'] . '/p2_rss/' . $pURL['host'] . '/' . $localname;
return $finished[$remotefile] = $localpath;
}
示例9: p2h
EOP;
} else {
$ptitle_ht = <<<EOP
<b>{$ptitle_hd}</b>
EOP;
}
// }}}
// フォーム ==================================================
$sb_form_hidden_ht = <<<EOP
<input type="hidden" name="bbs" value="{$aThreadList->bbs}">
<input type="hidden" name="host" value="{$aThreadList->host}">
<input type="hidden" name="spmode" value="{$aThreadList->spmode}">
{$_conf['detect_hint_input_ht']}{$_conf['k_input_ht']}{$_conf['m_favita_set_input_ht']}
EOP;
// フィルタ検索 ==================================================
$hd['word'] = p2h($word);
$filter_form_ht = '';
$hit_ht = '';
if (!$spmode_without_palace_or_favita) {
if (array_key_exists('method', $sb_filter) && $sb_filter['method'] == 'or') {
$hd['method_checked_at'] = ' checked';
} else {
$hd['method_checked_at'] = '';
}
$filter_form_ht = <<<EOP
<form method="GET" action="{$_conf['subject_php']}" accept-charset="{$_conf['accept_charset']}">
{$sb_form_hidden_ht}<input type="text" id="sb_filter_word" name="word" value="{$hd['word']}" size="15">
<input type="checkbox" id="sb_filter_method" name="method" value="or"{$hd['method_checked_at']}><label for="sb_filter_method">OR</label>
<input type="submit" name="submit_kensaku" value="検索">
</form>
示例10: updateFavSetList
/**
* お気に入りセットリストを更新する
*
* @return boolean 更新に成功したらtrue, 失敗したらfalse
*/
function updateFavSetList()
{
global $_conf;
if (file_exists($_conf['expack.misc.favset_file'])) {
$setlist_titles = FavSetManager::getFavSetTitles();
} else {
FileCtl::make_datafile($_conf['expack.misc.favset_file']);
}
if (empty($setlist_titles)) {
$setlist_titles = array();
}
$setlist_names = array('m_favlist_set', 'm_favita_set', 'm_rss_set');
foreach ($setlist_names as $setlist_name) {
if (isset($_POST["{$setlist_name}_titles"]) && is_array($_POST["{$setlist_name}_titles"])) {
$setlist_titles[$setlist_name] = array();
for ($i = 0; $i <= $_conf['expack.misc.favset_num']; $i++) {
if (!isset($_POST["{$setlist_name}_titles"][$i])) {
$setlist_titles[$setlist_name][$i] = '';
continue;
}
$newname = trim($_POST["{$setlist_name}_titles"][$i]);
$newname = preg_replace('/\\r\\n\\t/', ' ', $newname);
$newname = p2h($newname);
$setlist_titles[$setlist_name][$i] = $newname;
}
}
}
$newdata = serialize($setlist_titles);
if (FileCtl::file_write_contents($_conf['expack.misc.favset_file'], $newdata) === false) {
P2Util::pushInfoHtml("<p>p2 error: {$_conf['expack.misc.favset_file']} にお気に入りセット設定を書き込めませんでした。");
return false;
}
return true;
}
示例11: printf
$row_format = <<<EOP
<input type="text" name="nga[%1\$d][word]" value="%2\$s"><br>
板:<input type="text" size="5" name="nga[%1\$d][bbs]" value="%5\$s">
<input type="checkbox" name="nga[%1\$d][ignorecase]" value="1"%3\$s>i
<input type="checkbox" name="nga[%1\$d][regex]" value="1"%4\$s>re
<input type="text" name="nga[%1\$d][del]" value="1">×<br>
<input type="hidden" name="nga[%1\$d][lasttime]" value="%6\$s">
<input type="hidden" name="nga[%1\$d][hits]" value="%7\$d">(%6\$d)<br>
EOP;
}
printf($row_format, -1, '', '', '', '', '--', 0);
echo $htm['form_submit'];
if (!empty($formdata)) {
foreach ($formdata as $k => $v) {
printf($row_format, $k, p2h($v['word']), $v['ignorecase'], $v['regex'], p2h($v['bbs']), p2h($v['lasttime']), p2h($v['hits']));
}
echo $htm['form_submit'];
}
// PCなら
if (!$_conf['ktai']) {
echo '</table>' . "\n";
}
echo '</form>' . "\n";
// 携帯なら
if ($_conf['ktai']) {
echo <<<EOP
<hr>
<a {$_conf['accesskey']}="{$_conf['k_accesskey']['up']}" href="editpref.php{$_conf['k_at_q']}">{$_conf['k_accesskey']['up']}.設定編集</a>
{$_conf['k_to_index_ht']}
EOP;
示例12: printf
$row_format = <<<EOP
Mat:<input type="text" name="dat[%1\$d][match]" value="%2\$s"><br>
Rep:<input type="text" name="dat[%1\$d][replace]" value="%3\$s"><br>
Ref:<input type="text" name="dat[%1\$d][referer]" value="%4\$s"><br>
<input type="text" name="dat[%1\$d][extract]" value="{$EXTRACT}"%5\$s>Exp<br>
Src:<input type="text" name="dat[%1\$d][source]" value="%6\$s"><br>
<input type="text" name="dat[%1\$d][del]" value="1">×<br>
EOP;
}
printf($row_format, -1, '', '', '', '', '', '', '');
echo $htm['form_submit'];
if (!empty($formdata)) {
foreach ($formdata as $k => $v) {
printf($row_format, $k, p2h($v['match']), p2h($v['replace']), p2h($v['referer']), p2h($v['extract']), p2h($v['source']), $v['recheck'] ? ' checked' : '', p2h($v['ident']));
}
echo $htm['form_submit'];
}
// PCなら
if (!$_conf['ktai']) {
echo '</table>' . "\n";
}
echo '</form>' . "\n";
// 携帯なら
if ($_conf['ktai']) {
echo <<<EOP
<hr>
<a {$_conf['accesskey']}="{$_conf['k_accesskey']['up']}" href="editpref.php{$_conf['k_at_q']}">{$_conf['k_accesskey']['up']}.設定編集</a>
{$_conf['k_to_index_ht']}
EOP;
示例13: printFavIta
/**
* お気に板をプリントする for 携帯
*/
public function printFavIta()
{
global $_conf;
$show_flag = false;
// favita読み込み
if ($lines = FileCtl::file_read_lines($_conf['favita_brd'], FILE_IGNORE_NEW_LINES)) {
if ($_conf['expack.misc.multi_favs']) {
$favset_title = FavSetManager::getFavSetPageTitleHt('m_favita_set', 'お気に板');
} else {
$favset_title = 'お気に板';
}
echo "<div>{$favset_title}";
if ($_conf['merge_favita']) {
echo " (<a href=\"{$_conf['subject_php']}?spmode=merge_favita{$_conf['k_at_a']}{$_conf['m_favita_set_at_a']}\">まとめ</a>)";
}
echo " [<a href=\"editfavita.php{$_conf['k_at_q']}{$_conf['m_favita_set_at_a']}\">編集</a>]<hr>";
$i = 0;
foreach ($lines as $l) {
$i++;
if (preg_match("/^\t?(.+)\t(.+)\t(.+)\$/", $l, $matches)) {
$itaj = rtrim($matches[3]);
$itaj_view = p2h($itaj);
$itaj_en = UrlSafeBase64::encode($itaj);
if ($i <= 9) {
$accesskey_at = $_conf['k_accesskey_at'][$i];
$accesskey_st = $_conf['k_accesskey_st'][$i];
} else {
$accesskey_at = '';
$accesskey_st = '';
}
echo <<<EOP
<a href="{$_conf['subject_php']}?host={$matches[1]}&bbs={$matches[2]}&itaj_en={$itaj_en}{$_conf['k_at_a']}"{$accesskey_at}>{$accesskey_st}{$itaj_view}</a><br>
EOP;
// [<a href="{$_SERVER['SCRIPT_NAME']}?host={$matches[1]}&bbs={$matches[2]}&setfavita=0&view=favita{$_conf['k_at_a']}{$_conf['m_favita_set_at_a']}">削</a>]
$show_flag = true;
}
}
echo "</div>";
}
if (empty($show_flag)) {
echo "<p>お気に板はまだないようだ</p>";
}
}
示例14: elseif
} elseif (P2Util::isHostMachiBbsNet($aThreadList->host)) {
// まちビねっと
$ini_url_text = "http://{$aThreadList->host}/test/read.cgi?bbs={$aThreadList->bbs}&key=";
} else {
$ini_url_text = "http://{$aThreadList->host}/test/read.cgi/{$aThreadList->bbs}/";
}
}
//if(!$aThreadList->spmode || $aThreadList->spmode=="fav" || $aThreadList->spmode=="recent" || $aThreadList->spmode=="res_hist"){
$onclick_ht = <<<EOP
var url_v=document.forms["urlform"].elements["url_text"].value;
if (url_v=="" || url_v=="{$ini_url_text}") {
alert("見たいスレッドのURLを入力して下さい。 例:http://pc.2ch.net/test/read.cgi/mac/1034199997/");
return false;
}
EOP;
$onclick_ht = p2h($onclick_ht);
echo <<<EOP
<form id="urlform" method="GET" action="{$_conf['read_php']}" target="read">
スレURLを直接指定
<input id="url_text" type="text" value="{$ini_url_text}" name="url" size="62">
<input type="submit" name="btnG" value="表\示" onclick="{$onclick_ht}">
</form>
EOP;
if ($aThreadList->spmode == 'fav' && $_conf['expack.misc.multi_favs']) {
echo "\t<div style=\"margin:8px 8px;\">\n";
echo FavSetManager::makeFavSetSwitchForm('m_favlist_set', 'お気にスレ', null, null, false, array('spmode' => 'fav', 'norefresh' => 1));
echo "\t</div>\n";
}
//}
//================
示例15: foreach
if (!$aThreadList->spmode || $aThreadList->spmode == "taborn" || $aThreadList->spmode == "soko") {
$htm['change_sort'] .= "<input type=\"hidden\" name=\"host\" value=\"{$aThreadList->host}\">";
$htm['change_sort'] .= "<input type=\"hidden\" name=\"bbs\" value=\"{$aThreadList->bbs}\">";
}
$htm['change_sort'] .= '<select name="sort">';
foreach ($sorts as $k => $v) {
if ($GLOBALS['now_sort'] == $k) {
$sb_sort_selected_at = ' selected';
} else {
$sb_sort_selected_at = '';
}
$htm['change_sort'] .= "<option value=\"{$k}\"{$sb_sort_selected_at}>{$v}</option>";
}
$htm['change_sort'] .= '</select>';
if (!empty($_REQUEST['sb_view'])) {
$htm['change_sort'] .= '<input type="hidden" name="sb_view" value="' . p2h($_REQUEST['sb_view']) . '">';
}
if (!empty($_REQUEST['rsort'])) {
$sb_rsort_checked_at = ' checked';
} else {
$sb_rsort_checked_at = '';
}
$htm['change_sort'] .= ' <input type="checkbox" id="sb_rsort" name="rsort" value="1"' . $sb_rsort_checked_at . '><label for="sb_rsort">逆順</label>';
$htm['change_sort'] .= ' <input type="submit" value="並び替え"></form>';
// }}}
// HTMLプリント ==============================================
echo '<hr>';
echo $k_sb_navi_ht;
include P2_LIB_DIR . '/sb_toolbar_k.inc.php';
echo $allfav_ht;
echo $switchfavlist_ht;