note 97235 added to function.trim

From: Date: Fri, 09 Apr 2010 11:29:39 +0000
Subject: note 97235 added to function.trim
Groups: php.notes 
Request: Send a blank email to php-notes+get-168069@lists.php.net to get a copy of this message
<?php // trims occurances of every word in an array from the beginning and end of a string + whitespace // and optionally extra single characters as per normal trim() function trim_words($what, $words, $char_list = '') { if(!is_array($words)) return false; $char_list .= " \t\n\r\0\x0B"; // default trim chars $pattern = "(".implode("|", array_map('preg_quote', $words)).")\b"; $str = trim(preg_replace('~'.$pattern.'$~i', '', preg_replace('~^'.$pattern.'~i', '', trim($what, $char_list))), $char_list); return $str; } // for example: $trim_list = array('AND', 'OR'); $what = ' OR x = 1 AND b = 2 AND '; print_r(trim_words($what, $trim_list)); // => "x = 1 AND b = 2" $what = ' ORDER BY x DESC, b ASC, '; print_r(trim_words($what, $trim_list, ',')); // => "ORDER BY x DESC, b ASC" ?> ---- Server IP: 69.147.83.197 Probable Submitter: 118.90.1.31 ---- Manual Page -- http://www.php.net/manual/en/function.trim.php Edit -- https://master.php.net/note/edit/97235 Del: integrated -- https://master.php.net/note/delete/97235/integrated Del: useless -- https://master.php.net/note/delete/97235/useless Del: bad code -- https://master.php.net/note/delete/97235/bad+code Del: spam -- https://master.php.net/note/delete/97235/spam Del: non-english -- https://master.php.net/note/delete/97235/non-english Del: in docs -- https://master.php.net/note/delete/97235/in+docs Del: other reasons-- https://master.php.net/note/delete/97235 Reject -- https://master.php.net/note/reject/97235 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168069) next »