flash gordon Posted January 20, 2007 Share Posted January 20, 2007 I can't seem to get this for the life of me. Maybe a hint would help. Here is what I'm trying to do[code]<Parent id="7"> <child /> <child /></Parent><Parent id="2"> <child /> <child /></Parent><Parent id="44"> <child /> <child /></Parent>[/code]To make it look like this:[code]<Parent id="0"> <child /> <child /></Parent><Parent id="1"> <child /> <child /></Parent><Parent id="2"> <child /> <child /></Parent>[/code]I'm sure there is an easy way and I'm over complicating the issue. Any tips?:)btw, I have tried preg_replace() but I seem to replace all patterns with the same string. I need the id to increment.... Link to comment https://forums.phpfreaks.com/topic/35009-replace-all-string-patterns-with-a-string-variable/ Share on other sites More sharing options...
.josh Posted January 20, 2007 Share Posted January 20, 2007 are you reading this file line by line or is ^ one giant string?if it's one giant string, I think you're probably going to have to use preg_match_all or explode to break it up somehow, so that you can loop your preg_replace. Link to comment https://forums.phpfreaks.com/topic/35009-replace-all-string-patterns-with-a-string-variable/#findComment-165118 Share on other sites More sharing options...
flash gordon Posted January 22, 2007 Author Share Posted January 22, 2007 I'm reading it with fopen, so however that reads it, but I do store the entire page as one String variable. I eventually did get it to work for a client, but I'm positive there are better ways.Thanks for the reply.:) Link to comment https://forums.phpfreaks.com/topic/35009-replace-all-string-patterns-with-a-string-variable/#findComment-166018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.