atlanta Posted April 17, 2008 Share Posted April 17, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/101466-selecting-content-in-between/ Share on other sites More sharing options...
Orio Posted April 17, 2008 Share Posted April 17, 2008 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/101466-selecting-content-in-between/#findComment-519432 Share on other sites More sharing options...
TripleDES Posted June 20, 2008 Share Posted June 20, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/101466-selecting-content-in-between/#findComment-570366 Share on other sites More sharing options...
nashruddin Posted June 24, 2008 Share Posted June 24, 2008 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"; */ Quote Link to comment https://forums.phpfreaks.com/topic/101466-selecting-content-in-between/#findComment-573139 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.