|
Posted by Chung Leong on 01/31/06 01:40
matthewburton@gmail.com wrote:
> Hi everyone,
>
> I'm trying to write a program that will search a body of text and
> replace certain words (say, A, B, and C) with different words that I
> think are more appropriate (A1, B1 and C1). I have a feeling that I
> need to do this through a multidimensional array. Am I on the right
> track?
>
> thanks,
> matt
I don't really see a need for multidimensional arrays here. A single
associative array would serve perfectly well. For example, the
following is the simplest way to do what you described:
$table = array("A" => "A1", "B" => "B1", "C" => "C1");
$text = strtr($text, $table);
For something requiring more sophisticated handling, you might want to
use preg_replace(), passing twos arrays as parameters.
[Back to original message]
|