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!!!

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.