Jump to content

String manipulation


alvin567

Recommended Posts

1) I don't see how that link provided any more details that what you already posted here...

2) Does the code I posted not do what you asked?

 

Here is a breakdown of what it does:

 

$string = "1811-011";
$string = preg_replace_callback( // function to match and replace a value with a LPI prefix and possible 2k if it is a 2k date
  '~^[0-9]{2}~',                 // match the first 2 digits in the string (example 19 in 1969)
  create_function(               // create anonymous function to handle the matched value
    '$m',                        // passing the matched value to the anonymous function
    'return                      // return the following:
      "LPI ".                    // the LPI prefix you want to add
      (($m[0]==20)?              // is the matched 2 digits 20?
        "2K":                    // if yes, add the 2K prefix 
        "");'                    // if no, nothing more to add
  ),                             // end of create_function call
  $string                        // the original string value to perform the regex on
);                               // end of preg_replace_callback call

Link to comment
https://forums.phpfreaks.com/topic/263683-string-manipulation/#findComment-1351542
Share on other sites

Archived

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

×
×
  • Create New...

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.