PHP Trim Usage Solver
Take a first three-bit string of IP, the great god help me to see the string '. ' No, it's not going to go off.
PHP Code
$str = ' 192.168.175.45 '; $arr = explode ('. ', $str); Array_pop ($arr); $output = '; foreach ($arr as $k) { $output. = '. '. $k; }ltrim ($output, '. '); Print_r ($output);
Output. 192.168.175
------Solution--------------------
$output =ltrim ($output, '. ');
Print_r ($output);
------Solution--------------------
$output = LTrim ($output, '. ');
But there is no need for LTrim () Processing:
PHP code
$str = ' 192.168.175.45 '; $arr = explode ('. ', $str); Array_pop ($arr); $output = Implode ('. ', $arr);p Rint_r ($output);
------Solution--------------------
can also be written like this:
PHP code
------Solution--------------------
Your source
PHP code
$ Str= ' 192.168.175.45 '; $arr = explode ('. ', $str); Array_pop ($arr); $output = "; foreach ($arr as $k) {$output. = '. '. $k; } $output = LTrim ($output, '. '); Print_r ($output);