Forum Moderators: coopster

Message Too Old, No Replies

Cross-platform newline problems

         

davidjones

6:05 pm on Sep 7, 2006 (gmt 0)

10+ Year Member



Hello,

I'm got a bit of problem here and was hoping perhaps someone could help me out. I have done a lot of searching and trying anything to narrow down and sort it out but no luck.

On my local machine which I'm using for development, I'm running Apache on windows. I edit my files with Ultra-edit and upload them with SmartFTP.

I upload to my VPS which is using CentOS. Occasionally I'll edit these files online through DirectAdmin.

The dodgy code is for editing templates. These are stored in .php files in the format:

function NAME(PARAMS) {
return <<<HTML
<p>My template html goes here</p>
<img src="image.gif" alt="etc.">
HTML;
}

and I'm using a preg_match to extract that HTML from the template. However, its not working very well and I guess it's just compatability issues. Having moved it all onto one line and been able to edit the template successfully, it must be because of the newline character.

I did originally try variations of \n\r as the newline character but it didn't work on both machines. I then used a newline in the matching function itself, which appeared to work at first but after transferring the files back and forth a few times, I can't ever get it working on both machines using the same code.

The matching pattern I'm using is as follows:

preg_match('/function '. $Name .'\((.*)\) \{
return <<<HTML
(.*)
HTML;/isUm', $File, $Match)

Any help is much appreciated. I hope I've given enough information.

Many thanks!

coopster

7:46 pm on Sep 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, davidjones.

Why not just match any whitespace at all there? Then you know you get the newline characters, whatever they might be. Set the Ungreedy modifier, but then reverse it on the space characters ...

$pattern = "/function $Name\s*?\(([^\)]+)\)\s*?\{\s*?return <<<HTML\s*?(.*)\s*?HTML;/Uis";

davidjones

8:35 pm on Sep 7, 2006 (gmt 0)

10+ Year Member



Thanks mate, you're an absolute star! Working perfectly now, cheers.

I'm still not completely comfortable with regex but making progress slowly.. I think.

Thanks again. ;)