Jump to content

Selecting Content in Between


atlanta

Recommended Posts

Hey i needed a little help with selecting the stuff in between this code

 

table table table {

border-style:solid;

border-width:1px;

border-color:A47040;

background-color:EEE3CF; 

 

So i would want the regex function to return

border-style:solid;

border-width:1px;

border-color:A47040;

background-color:EEE3CF;

 

could someone help me out with writting the expression correctly thanks

Link to comment
Share on other sites

<?php

$data = <<<DATA
table table table {
border-style:solid;
border-width:1px;
border-color:A47040;
background-color:EEE3CF; 
}
DATA;

preg_match("|table table table {(.*?)}|is", $data, $match);

$result = trim($match[1]);
echo "<pre>{$result}</pre>";

?>

 

 

Orio.

Link to comment
Share on other sites

  • 2 months later...

Can this be done without a trim?  Or do you always need to trim when you want to match items in between delimiters?

 

ie. I have this:

 

<highlight>text</highlight>

 

And I only want to display

text

 

Would I need to trim off

<highlight>

 

Or can this be done through regex?

Link to comment
Share on other sites

trim() is not required, we use it just to remove spaces from the beginning and end of a string. Example: if you have this string:

 

<highlight>  some text here     </highlight>

 

we can remove <highlight> and </highlight> using this code:

 

$str = preg_replace("/<\/?highlight>/", "", $str);

 

which will result in

 

$str = "  some text here     ";

 

and use trim (optional) to remove the spaces.

 

$str = trim($str)
/* $str = "some text here"; */

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.