$theTitle=wp_title(" - ", false); if($theTitle != "") { ?>
WordPressのカスタマイズとプラグイン、CSSテクニック、SEOの話題など。
In: php
19 1月 2010手っ取り早く、ページ内に他のページのヘッダー部分とかメニューの一部とかを表示したい、と思うことが結構あるので、再利用できるように関数化しました。
function ripping_html($source,$start,$end){ $html_source = file_get_contents("$source"); $rip_source = preg_replace('/\n/', ' ', $html_source); $pattern= "/$start(.*)$end/"; preg_match($pattern, $rip_source, $match); echo $match[0]; }
引っ張ってくる対象ページのURLと、HTMLソース内の開始シグナル、終了シグナルを引数で指定します。
string ripping_html ( resource $context, string $start , string $end )
例
ripping_html('http://blog.dacelo.info/example.html', '<html>', '<end>');
Related posts:
Related posts brought to you by Yet Another Related Posts Plugin.
ここは、SE見習いである私ことdaceloが、日夜習得していくシステム関連の備忘録、phpやWordPressTipsのネタ、あるいはSEOやWebマーケティング関連の雑感を投稿するブログです。 平日は大体毎日投稿しています。土日は休業日です。
1 Response to 別のページから一部分を引っ張ってくるphp関数
トラックバックURL:daceloweb
1月 19th, 2010 at 2:36 PM
投稿しました~: (http://blog.dacelo.info/php/entry-767.html)