On 31 Oct 2005, at 06:27, Richard Lynch wrote:
There's a certain point where the Regex expression reaches a level of
complexity that I'm just not willing to accept in my code and call it
maintainable
/ */ is fine, of course.
But there's lots of times when I know there must be a one-line
On 29 Oct 2005, at 20:41, Richard Lynch wrote:
It was probably replacing *TWO* spaces with one.
If so, it should really be in a while loop, because there could be 3
or more spaces in a row, and if the goal is only single-spaced
words...
I can hardly think of a better application for a regex:
On Sun, October 30, 2005 6:04 am, Marcus Bointon wrote:
On 29 Oct 2005, at 20:41, Richard Lynch wrote:
It was probably replacing *TWO* spaces with one.
If so, it should really be in a while loop, because there could be 3
or more spaces in a row, and if the goal is only single-spaced
Finally i found it (Google is god, you only have to ask the right question)
function trim_text($text, $count){
$text = str_replace( , , $text);
$string = explode( , $text);
for ( $wordCounter = 0; $wordCounter = $count;wordCounter++ ){
$trimed .= $string[$wordCounter];
if ( $wordCounter $count
Good job!
However, let me give a few suggestions to optimize the code
function trim_text($text, $count)
{
$text = str_replace( , , $text);
/*
* This is redundant; you are replacing all in $text with
* maybe you meant
* $text = trim($text); ?
*/
Good start guys. That's usually how I start down the path in solving a new
problem. Invariably down the road I find a more refined way of doing what I
did the hard way. The hard way is good though, you learn stuff along the way.
Let's see how tight we can make this though:
?php
$string =
On Sat, October 29, 2005 10:51 am, Minuk Choi wrote:
function trim_text($text, $count)
{
$text = str_replace( , , $text);
/*
* This is redundant; you are replacing all in $text with
* maybe you meant
* $text = trim($text); ?
*/
It was
7 matches
Mail list logo