PHP & newlines Regular expressions

They have: 53 posts

Joined: Oct 2005

Hi all!
I have a preformatted text where I want to run a regular expression. The text is something like :

<?php
codeA
*->refbrjkgbrkjgbrjukbgreukgbrukgbegurebgrek

klgfhnrjkgnrjgbrejkgbrjkbegjkrbbrkegbrejb

reopjgporejytopjrotjrphjpojprhjtporhtjrph

codeB
*->4p3tuop43tu4optj4rofdgfnreklfnrklefnrkenr

ropeturojgorejgeolgjrelgjrlgrhelkghelghlg

regjrejgoejeojigjreilgjelgjrilgjlerjgelrj
?>

From each 'paragraph', I want to match the part under codeA and codeB
The problem I have is with matching the newline characters. I write :
preg_match('/code.{1}\n\*->(.*)\ncode./')
but it doesn't match... I think the problem is the newlines

dk01's picture

He has: 516 posts

Joined: Mar 2002

Try using \r\n because \n is solely for Windows systems. I am assuming your php server is linux and these files were made on that server.

dk01's picture

He has: 516 posts

Joined: Mar 2002

Also I found this page and they have quite a bit of information on special sequences:
http://www.phpro.org/tutorials/regex.php

-Jim

They have: 53 posts

Joined: Oct 2005

Hi,
thanx for the posts...
I tried using double quotes, but doesn't do anything... and the weird thing is that, for instance, spaces are matced with \s but why newlines don't????I can't figure it out.....
I am currently on Windows, but will try it...

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.