Jump to content

Archived

This topic is now archived and is closed to further replies.

phporcaffeine

unique string manipulation *SOLVED*

Recommended Posts

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

Share this post


Link to post
Share on other sites
so basically, what you want is to replace the numeric value in that string without affecting the rest of the string?

Share this post


Link to post
Share on other sites
[code]
$mystring = "date >= '41968880'";
$replacement = 'test';

$mystring = preg_replace("/(.*?')(.*?)(')/", "$1$replacement$3", $mystring);

echo $mystring;    // displays: date >= 'test'
[/code]

Share this post


Link to post
Share on other sites
[!--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, ;)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.