Posted by Edward Z. Yang on 05/22/07 19:12
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Peter Parker wrote:
> What is the best way to delete tags n times from either the beginning or the
> end of a String? For example, to delete "someString1" and "someString2"
> along with surrounding <someTag>'s with n=2 and processing direction is from
> beginning.
If you're dealing with valid XML, it may be a good idea to parse it
using one of PHP's XML extensions, do the manipulations you want with
DOM/SimpleXML API, and then serialize it back to XML.
preg_replace will only work from the front, although you can use the
$limit parameter to get the "n times" functionality.
- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.org> Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGU0CrqTO+fYacSNoRApiPAJ9FTMMhkPXj/3GGy5AMNKfoANbofACfaj/6
Pb8sEhZ7CjVfPfa3dVP97dg=
=qrwe
-----END PGP SIGNATURE-----
[Back to original message]
|