Reply to Re: [PHP] Replacing 2 strings

Your name:

Reply:


Posted by W Luke on 10/23/08 11:17

On 30/05/05, Brian V Bonini <b-bonini@cox.net> wrote:
> On Mon, 2005-05-30 at 11:13, Murray @ PlanetThoughtful wrote:
> > > Someone much more clever that I can probably come up with something much
> > > cleaner and efficient but.... This works...
> >
> > Definitely not more clever and arguably not more efficient, but a different
> > way of handling this might be:
> >
> > <?
> >
> > function replace($string){
> > $string = preg_replace("/(<|\^|>)/", "",$string);
> > $string = str_replace("_", " ", $string);
> > $string = ucwords(strtolower($string));
> > $string = str_replace(" ", "-", $string);
> > return $string;
> > }
> >
> > echo replace("<^JIM_JONES>");
> >
> > ?>
>
> AHHH! ucwords(); I probably looked right at it a million times.. I knew
> there had to be something to do that....

This is a great help, thanks to both. One question I have though.
How do I just leave the formatting "as is"? In the loop you gave me,
Brian...:

foreach($pieces as $char) {
$first_letter[] = $char{0};
$remainder[] = strtolower(substr($char, 1));
}

$result = array_merge($first_letter, $remainder);
list($frstltr,$lstltr,$frstwrd,$lstwrd) = $result;
$string = $frstltr . $frstwrd . " v " . $lstltr . $lstwrd;

return $string;
}

I can't see how I can disregard strtolower without disrupting the rest
of the function! My problem is $string contains a whole load of text,
the formatting of which needs to be retained...

--
Will The Corridor of Uncertainty http://www.cricket.mailliw.com/
- Sanity is a madness put to good use -

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация