note 65561 deleted from function.preg-replace by nlopess

From: Date: Wed, 03 May 2006 18:45:25 +0000
Subject: note 65561 deleted from function.preg-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-110465@lists.php.net to get a copy of this message
Note Submitter: drquincy at gmail dot com ---- 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/

« previous php.notes (#110465) next »