note 18924 added to function.preg-replace
| From: | skd2 at ece dot msstate dot edu | Date: | Sun, 10 Feb 2002 03:17:38 +0000 |
| Subject: | note 18924 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26432@lists.php.net to get a copy of this message | ||
To whoever is working on on-the-fly conversion
from HTML to WML - while converting, we remove all
the tags, but in order to navigate we have to
preserve the links on the html page onto
the corresponding WML page for which I suggest the
following - took a while to figure it out...
After the HTML content is read into $document variable:
$document =
preg_replace("'<a
href=[\"|\'](.*[^>])[\"|\']>(.*[^<>])</a>'i",
"<a href=\"converter.php?
file=\\1\"> \\2 </a><br/>",$document);
$search = array("'&(lt|#60);'i", "'&(gt|#62);'i");
$replace = array("<",">");
$document = preg_replace($search, $replace, $document);
The program file that would do the on-the-fly convertion
is named as 'converter.php'.The code will rewrite and copy
the links onto the WML page. The links have to be rewritten
to be parsed by the code because they still point to
HTML pages. So, whenever a link (that points to the
html page) is clicked, on the WML page, the page is
retrieved and converted into WML format and ofcourse
the links are rewritten again, as a recursive process.
If the link on HTML page was :
<a href="/test/index.html">Test</a>
On the WML page, it would show up as :
<a href="converter.php?file=/test/index.html">Test</a>
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+18924
http://master.php.net/manage/user-notes.php?action=delete+18924
http://master.php.net/manage/user-notes.php?action=reject+18924