Hi I want to remove words that end with : within a string. For example if I write "test: 1234" it will remove "test:" and only echo " 1234" Can anyone help me with this? Thanks in advance
Preg_replace version: preg_replace('/([a-zA-Z]*):/','',$str); PHP: or if you preference the old fashioned, explode way: $str="test: 1234"; $final=array(); $str=explode(' ', $str); $n=count($str); for ($i=0; $i<$n;$i++) if (strpos($str[$i], ':')===false) $final[]=$str[$i]; $clean_string=implode(' ', $final); echo $clean_string; PHP:
Using this: preg_replace('/([a-zA-Z]*):/','',$str); PHP: How can I make it replace if it is "test:" and if it is "test :" (with a space between the word and semicolon) ? Thanks in advance
Thanks alot Just one final question .. How can I make that code inverted? So it removes any word AFTER the semicolons?
<?php /* [weilemei.net] (C)2010-2019 weilemei.net Inc. This is a freeware $Id:test.php 2010-07-01 11:41:07Z weilemei $ */ function remove_str($str,$string) { return str_replace("$str","",$string); } //e.g $string = '123123sdfd12323'; $str ='fd'; $return = remove_str($str,$string); echo $return; ?> Holp it can help u.
<?php /* [weilemei.net] (C)2010-2019 weilemei.net Inc. This is a freeware $Id:test.php 2010-07-01 11:41:07Z weilemei $ */ function remove_str($str,$string) { return str_replace("$str","",$string); } //e.g $string = '123123sdfd12323'; $str ='fd'; $return = remove_str($str,$string); echo $return; ?> PHP: Holp it can help u.
You can use str_replace() function to remove particular string from the string, you can replace with blank space and you can remove string