note 65561 added to function.preg-replace

From: Date: Wed, 03 May 2006 13:08:11 +0000
Subject: note 65561 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-110451@lists.php.net to get a copy of this message
I recently had to parse HTML pages from a remote web server and run them through a portal on localhost; the portal took the page name as a URL variable. E.g. http://www.remotewebserver.com/pagename.php . . . would read . . . http://www.mydomain.com/portal.php?id=pagename.php. In case it's useful to anyone the following code will rewrite the hyperlink so that they work through the portal: <?php $newurlstructure = "portal.php?id="; $html = '<div><a href="thisisalink.php">Link</a></div>'; $html = preg_replace( '#(href)="([^:"]*)(?:")#', '$1="/' . $newurlstructure . '$2"', $html ); echo $html; ?> Thanks, Tim Bennett http://www.drquincy.com/ ---- Server IP: 84.18.202.180 Probable Submitter: 193.195.117.186 (proxied: 1.1 BOISE) ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/note/edit/65561 Del: integrated -- http://master.php.net/note/delete/65561/integrated Del: useless -- http://master.php.net/note/delete/65561/useless Del: bad code -- http://master.php.net/note/delete/65561/bad+code Del: spam -- http://master.php.net/note/delete/65561/spam Del: non-english -- http://master.php.net/note/delete/65561/non-english Del: in docs -- http://master.php.net/note/delete/65561/in+docs Del: other reasons-- http://master.php.net/note/delete/65561 Reject -- http://master.php.net/note/reject/65561 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#110451) next »