Re: Web Fetch & Process

From: Date: Tue, 07 Sep 2004 01:58:15 +0000
Subject: Re: Web Fetch & Process
Groups: php.general 
Request: Send a blank email to php-general+get-196007@lists.php.net to get a copy of this message
Hi How can I parse HTML page which I fetched by PHP so some part of text would be replaced by other text. Also, I managed to delete all HTML code from page (with this code $data[0] = preg_replace("/([<])+([^>])+([.])*([>])+/i","", $data[0]); but also would like to delete all chars except numbers from page, can this be done? Regards. Zoran Your first question: To replace certain elements take a look at preg_replace() http://us4.php.net/manual/en/function.preg-replace.php Example: $foo = 'stuff <b>silly stuff</b> more stuff'; echo preg_replace('/\<b\>(.*)\<\/b\>/', "<h1>$1 lookie now</h1>", $foo); Your second question: You could just use strip_tags() http://us4.php.net/manual/en/function.strip-tags.php Your last question: To delete everything but numbers you could $content = preg_replace('/[^\d]/','', $content); Hope that helps Jim Grill Hi This works great. One more question about preg_replace. Is it possible that for every match other text is replaced? By this I mean when some text between <b></b> has been found that text is replaced with some Text, on second match, text between <b></b> is replaced by some other different text etc. Btw, where I can find patterns that are valid? (something like (\w+), (\d+)+i etc. Thanks. Regards.

« previous php.general (#196007) next »