PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1847
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Space Characters Getting Converted to Unknown Character Posted by Super26 on 24 Jun 2011 at 7:47 AM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.