Jump to content

Regular Expressions


Recommended Posts

Posted

Im trying to write a function in php that will split a string up using regular expressions. The problem is i suck at regular expressions which is making this even harder. What im trying to do is split something up that looks like

some stuff here

anything can be in here

some stuff here

i want to be able to pull down all the data inside the

 and

part, the thing is there can be more then one part inside the text so for example

some text

anything can be in here

some more text

anything can be in here

should give me both the code sections in an array, i was trying to use preg_split() to do this but i cant seem to get the correct regular expression.

---Edit---

Never mind i ended up working it out, there is a preg_match_all function in php which will place all the results inside an array, just in case anyone was wondering how i done it here is the code

function getCode($str) {

    $codeI = preg_match_all('/[code](.*?)
/is', $str, $code);

    for($i =0; $i <sizeof($code); $i++) {

        for($x =0; $x <sizeof($code[$i]); $x++) {

            echo $code[$i][$x] ."<br>";

        }

    }

}[/code]

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...