Can someone please tell me how to replace any code before a particular div, this is what i have so far:

$pattern1 = "/^<!doctype html>[a-zA-Z0-9._-]$/";
$replacement = '${1}1,$3';
preg_replace($pattern, $replacement, $ch);

I want it to replace absolutely anything it finds before a particular word which will be specified.

You can use * character instead of [a-zA-Z0-9._-].

* matches any character in regex language.

If you are not sure how to use this, please give an example case for what you want.

Hi, can someone please tell me how i would extract images from a page and display them only, or how to remove everything else, what i have so far is:

$link2 = $_GET[link];


$res = file_get_contents($link2);
	
$s[] = '#<(img|image)[^>]*?>#si';
$r[] = '';
	
$urlres = preg_match_all('#<(img|image)[^>]*?>#si', $res, $matches);
	
	print $urlres;

preg_match only prints out 1. I have tried preg_replace and it works for removing images, but how would i get it to remove everyhting else except the images.

I have solved the last question but :

Thanks, if a img tag has a relative src, how can i expand it to a fully qualified link

would

preg_match("|^http://".preg_quote($link2);

or


preg_match("/^[^\?]+/";
$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
		$match = preg_replace("|/$|","",$match);
		$match_part = parse_url($match);

be useful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.