|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-14 08:37 UTC] nek at capsule dot org
Description:
------------
Hi,
i'm trying to replace a portion of string by its strtolowered equivalent
see reproduce code and results below : it should give "href=javascript:comment()" but only "HREF" is lowered, not the matching string \1
Reproduce code:
---------------
<?php
$newsaff = "<A HREF=\"JAVASCRIPT:COMMENT()\">THIS IS A TEST LINK</A>";
$newsaff = ereg_replace("HREF=\"([^\"]+)\"",strtolower("HREF=\"\\1\""),$newsaff);
print $newsaff;
?>
Expected result:
----------------
<A href="javascript:comment()">THIS IS A TEST LINK</A>
Actual result:
--------------
<A href="JAVASCRIPT:COMMENT()">THIS IS A TEST LINK</A>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 18:00:01 2025 UTC |
Using strtolower("HREF=\"\\1\"") as parameter is like using "href=\"\\1\"" directly. First the strtolower is processed and then that result is used as parameter. You have to change your search/replace pattern to get what you want. The function works correct.you mean something like : <?php $newsaff = "<A HREF=\"JAVASCRIPT:COMMENT()\">THIS IS A TEST LINK</A>"; $newsaff = ereg("HREF=\"([^\"]+)\"",$newsaff,$newsreplace); for ($i=1;$i<sizeof($newreplace);$i++) print $newsaff; ?>doh... tab then return = submit form.. sorry i said : <?php $newsaff = "<A HREF=\"JAVASCRIPT:COMMENT()\">THIS IS A TEST LINK</A>"; $newsaff = ereg("HREF=\"([^\"]+)\"",$newsaff,$newsreplace); for ($i=1;$i<sizeof($newreplace);$i++) { $newsaff = str_replace($newreplace[$i],strtolower($newreplace[$i]),$newsaff); } print $newsaff; ?> maybe there's a simplier solution, that's coded from scratch ;) but yes indeed, that's complicated and a non bogus ereg_replace would be from great help :) thanks