RE: Replacing 2 strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2005-05-30 at 15:24, Murray @ PlanetThoughtful wrote:
> > 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...:
> 
> [snippage]
>  
> > 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...
> 
> Hmmm. Methinks your problem is a little more complex than originally
> presented.
> 
> Can you give us a pseudo-example of what the string might actually contain?
> I think both Brian and I took your original message to mean that your string
> would ONLY contain a value like "<^JIM_JONES>", but from this message I get
> the sense that the value you're trying to target may be buried in a string
> with other text on either side?
> 
> Again, an example that is as close to your real-world needs as possible
> would be very helpful.

The original request was: "the text-to-replace is just in a var named
$text1".

I read that to mean you'd already extracted "<^JIM_JONES>" into $text1


<?php

function replace($string, $search)
{
	$string = strstr($string, $search)
	$string = preg_replace("/(<|\^|>)/", "",$string);
	$string = str_replace("_", " ", $string);
	$string = ucwords(strtolower($string));
	$string = str_replace(" ", "-", $string);
	return $string;
                                                                                }

$text = 'My name is <^JIM_JONES> and I like ice cream';
$search_string = '<^JIM_JONES>';
echo replace($text, $search_string);

?>


-- 

s/:-[(/]/:-)/g


Brian        GnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
======================================================================
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
Key Info: http://gfx-design.com/keys
Linux Registered User #339825 at http://counter.li.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux