Hi, i have a text in a string like this: $mystring = "Aspect Ratio: 16:9"; or $mystring = "Contrast: 5.000.000:1"; etc... Code (markup): I want to replace only the first colon ":" inside the string and leave the others. how i can do this with php? thanks in advance.
<?php $mystring = "Contrast: 5.000.000:1"; $mystring = preg_replace('/:/','',$mystring,1); echo $mystring; // Contrast 5.000.000:1 ?> PHP:
faster than regex : $mystring = "Aspect Ratio: 16:9"; $result = substr($mystring, strpos($mystring, ":")); echo trim($result); PHP:
Oops yes correct, it will only print 16:9 / 5.000.000:1 thought that's what he wanted good point. Here's the solution : $mystring = "Aspect Ratio: 5.000.000:1"; echo implode("", explode(":", $mystring, 2)); PHP: