phporcaffeine Posted May 16, 2006 Share Posted May 16, 2006 Here is the basics of what I am attempting ... and it may be a combination of str & regex .... I don't know.<?php$mystring = "date >= '41968880'";//In the above, " date >= ' " is the given or 'constant', as well as the trailing " ' "//I need to, through PHP Identify whatever may be between " date >= ' " & " ' " and I also need to// be able to replace whatever is between " date >= ' " & " ' ".//I need to be able to do it without damage/change to the 'constant' or 'given' portion of the string.?>I would use str_replace but I cannot predict the text of what I would be replacing. I can only predict the 'constant' or 'given' portions of the string.Any help is appreciated!TIA Quote Link to comment https://forums.phpfreaks.com/topic/9820-unique-string-manipulation-solved/ Share on other sites More sharing options...
ryanlwh Posted May 16, 2006 Share Posted May 16, 2006 so basically, what you want is to replace the numeric value in that string without affecting the rest of the string? Quote Link to comment https://forums.phpfreaks.com/topic/9820-unique-string-manipulation-solved/#findComment-36418 Share on other sites More sharing options...
toplay Posted May 17, 2006 Share Posted May 17, 2006 [code]$mystring = "date >= '41968880'";$replacement = 'test';$mystring = preg_replace("/(.*?')(.*?)(')/", "$1$replacement$3", $mystring);echo $mystring; // displays: date >= 'test'[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9820-unique-string-manipulation-solved/#findComment-36482 Share on other sites More sharing options...
phporcaffeine Posted May 17, 2006 Author Share Posted May 17, 2006 [!--quoteo(post=374532:date=May 16 2006, 10:40 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ May 16 2006, 10:40 PM) [snapback]374532[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$mystring = "date >= '41968880'";$replacement = 'test';$mystring = preg_replace("/(.*?')(.*?)(')/", "$1$replacement$3", $mystring);echo $mystring; // displays: date >= 'test'[/code][/quote]Works like a charm bro, ;) Quote Link to comment https://forums.phpfreaks.com/topic/9820-unique-string-manipulation-solved/#findComment-36573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.