I’m new to regular expressions, so I need your help.
I need to replace 8000 in the string '"ts";s:4:"8000";s:2:"tr";s:3:"200"'
<?php
$txt = '"ts";s:4:"8000";s:2:"tr";s:3:"200"';
$pattern = '#\"ts\"\;[a-z]{1}\:[0-9]{1}\:\"([0-9]*)#';
$replacement = '7000';
$txt = preg_replace($pattern,$replacement,$txt);
print($txt);
?>
This code outputs 7000";s:2:"tr";s:3:"200" which isn’t what I need.
What am I doing wrong here? Thanks!
You are replacing the whole pattern-string with “7000”, that’s whats wrong. Use grouping:
=> “ts”;s:4:”7000″;s:2:”tr”;s:3:”200″