0

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.

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by ade92uk
0

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.

0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.