Jump to content


Photo

unique string manipulation *SOLVED*


  • Please log in to reply
3 replies to this topic

#1 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 16 May 2006 - 10:57 PM

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
Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 16 May 2006 - 11:00 PM

so basically, what you want is to replace the numeric value in that string without affecting the rest of the string?
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 17 May 2006 - 02:40 AM

$mystring = "date >= '41968880'";
$replacement = 'test';

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

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


#4 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 17 May 2006 - 12:21 PM

[!--quoteo(post=374532:date=May 16 2006, 10:40 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ May 16 2006, 10:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$mystring = "date >= '41968880'";
$replacement = 'test';

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

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

Works like a charm bro, ;)
Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users