I’ve got a problem with my PHP code using Drupal. What I have is an array of names, which has a particular format and can contain characters as well as spaces. The name can be of two formats:
$name[0] = "--> Psychic Barrtier";
$name[1] =" Initial Presence";
In my code, I take each line in the array, and use a preg_match statement to see if it matches these two patterns. So, I am basically looking for a line that starts with two dashes and ‘>’ this, followed by a space. Or I am looking for a line that starts with 4 spaces. This is my preg_match statement:
while (preg_match('/^(--> |--> |--> | {4}|    |Â+)(.+)$/', $name[$i], $capturedname))
The problem is, both types of names are passing the preg_match statement, but when I encounter a name that starts with just the 4 spaces, the captured data in the variable $capturedname doesn’t match up. Basically, what I’m capturing in $caputredname[0] is the whole thing, then $capturedname[1] would be just the spaces, and $capturedname[2] would be just the name. This is what I get instead:
$capturedname[0]=" Evil Presence"
$capturedname[1] = “�”
$capturedname[2] = “� Evil Presence”
Array 1 plus 2 should equal Array 0, but that’s not the case here. The spaces are getting converted to some diamond with a question mark character and $capturedname[2] has the spaces again, it just doesn’t add up. Any sort of help would be greatly appreciated. It’s been bugging me for 3 days now. Thanks in advance.