|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
will code HTML for food
![]() ![]() ![]() ![]() Join Date: Sep 2000
Location: Corsica
Posts: 552
|
preg_replace'ing only the First match - it replaces the Last :(
I've got a problem with preg_replace... I'm using the last parameter to determine how many matches will be replaced, setting it to 1 so that only the first match is replaced.
It would all be fine, if only it replaced the first match. Instead, it replaces the last match. ![]() Is there any way to tell it in which order it should replace matches? |
|
|
|
|
|
#2 |
|
morphine for a wooden leg
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2002
Location: .chicago.il.us
Posts: 957
|
Re: preg_replace'ing only the First match - it replaces the Last :(
Show us what you're using. What's the string, the regex, the result?
__________________
----Adopt-a-Sig---- Your message here! |
|
|
|
|
|
#3 |
|
will code HTML for food
![]() ![]() ![]() ![]() Join Date: Sep 2000
Location: Corsica
Posts: 552
|
The complete code is there: http://tidakada.com/tagifythis.phps
I make it generate matches and replacement strings dynamically, so the preg_replace call looks like that: PHP Code:
#>([^<]{0,})([^a-zA-Z0-9]{1,})(CSS)([^a-zA-Z0-9]{1})([^>]{0,})<# And it would be replaced by: >$1$2<acronym title="Cascading Style Sheets">$3</acronym>$4$5< Last edited by Michel V; Oct 29, 2002 at 05:37.. |
|
|
|
|
|
#4 |
|
will code HTML for food
![]() ![]() ![]() ![]() Join Date: Sep 2000
Location: Corsica
Posts: 552
|
*bump*
I simplified the regex into: #>([^<]{0,}[^a-zA-Z0-9]{0,})(CSS)([^a-zA-Z0-9]{0,}[^>]{0,})<# To replaced it with: >$1<acronym title="Cascading Style Sheets">$2</acronym>$3< But it would still replace only the last match. Anyone have any ideas why it just replaces the last match, and/or how I could fix the regex so that it replaces the first match? |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 21:11.










Linear Mode
