I am a noob if this involves regex, and never so great with php either.

I made use of this code copying contents from another url:


$conts = file_get_contents('http://www.curtisjohnsonrealtyaz.com');

$pattern = '~<div.*id="home-right".*>(.*?)</div>~iUs';
preg_match($pattern, $conts, $matches);

echo $matches[0];


It labored fine aside from the extra line breaks as well as changed an moored image link to the present url.

I truly would appreciate outside assistance.


Try adding the "m" flag to your pattern, which should allow it to be stretch across linebreaks (multiline mode).

You ought to be make use of a dom parser to parse html, PHP Simple HTML DOM Parser is a great option.


$html = file_get_html('http://www.curtisjohnsonrealtyaz.com');
$div = $html->getElementById("home-right")->innertext;
echo $div;

PHP Simple HTML DOM Parser means less code and consistent results :)