On 07 Feb 18:40, Chris Green wrote:
I want a regular expression to select text between /x and /, e.g. I'm wanting to look at something like:-
/x This is a load of multi-line text and some more and more /
<snippity class="lots of info on what you've tried" />
This is using PHP regular expression searches.
And PHP regular expressions are odd at the best of times!
Anyways...
Hows about: brettp@erwin:~/temp/cg$ cat test.txt /x Line one Line two / Line three / Not a line that should be in the output / Another line that should not be in the output / brettp@erwin:~/temp/cg$ cat test.php <?php $filename = "test.txt"; $fh = fopen($filename, "r"); $data = fread($fh, filesize($filename)); $hasmatch = preg_match("/(^|[\r\n]+)\/x[\r\n]+(.*?)[\r\n]+\/[\r\n]+/s", $data, $matches); print $data; print "====\n"; if ($hasmatch > 0) { print $matches[2]; print "\n"; } ?> brettp@erwin:~/temp/cg$ php5 test.php /x Line one Line two / Line three / Not a line that should be in the output / Another line that should not be in the output / ==== Line one Line two / Line three brettp@erwin:~/temp/cg$
Hope that gives you the pointer you need.
Cheers,