Jump to content

[SOLVED] pulling information from formated string


micah1701

Recommended Posts

I have a string of text (created by reading a flat file) which looks something like:

<?php
$myDocument = "<H3>Some Random Header Information</H3> and here is the rest of the document. Blah blah blah you get the idea it goes on and on.";
?> 

 

I want to break this into a couple of variables; namely the Header information (which is always contained between an <H3> tag) and the body.  So the result would look like:

 

<?php
$header = "Some Random Header Information";
$body = "and here is the rest of the document. Blah blah blah you get the idea it goes on and on.";
?>

 

I'm not to great with regular expressions but I'm assuming thats my best bet?  My other thought was to "explode" it several times into arrays...but that doesn't seem like it would be in best practice.

 

Thoughts on what I should do?

 

Thanks!!!

Thanks! that's perfect.

I've just spent an hour messing around with preg_match and couldn't get it to work. It seems like every regex tutorial has different answers (at least when I try to interpret them).

 

Have a great day!!!

I encountered much of the same. Confusion.

 

than i found a nice tool Expresso - Regex development tool

its a great tool if yer starting out with regex.

 

the thing to note, when using preg and expresso

 

preg uses start and end delimeters followed by options

/pattern/options or @pattern@options

 

while Expresso just uses patterns (checkboxes for the options)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.