別のページから一部分を引っ張ってくる関数

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];
}

使い方

string ripping_html ( resource $context, string $start , string $end )

ripping_html(‘http://blog.dacelo.info/example.html’, ‘‘, ‘‘);

Comment Form

About this blog

ここは、SE見習いである私ことdaceloが、日夜習得していくシステム関連の備忘録、phpやWordPressTipsのネタ、あるいはSEOやWebマーケティング関連の雑感を投稿するブログです。 平日は大体毎日投稿しています。土日は休業日です。

紹介

カウンター

昨日:578 今日:97 合計;164652

カレンダー

2010年3月
« 2月    
1234567
891011121314
15161718192021
22232425262728
293031  

Translator

Japanese flagEnglish flagIndonesian flag
By N2H