The Little Guy Posted July 2, 2009 Share Posted July 2, 2009 I have the following in a text column in a database: <h2>The HTML Form</h2> Open up your index.php file, and copy and paste the following html into it: <form action="post.php" method="post"> <p>Name: <input type="text" name="name" /></p> <p>Message:<br /><textarea name="message" cols="30" rows="5"></textarea></p> <p><input type="submit" value="Post!" /></p> </form> This is a basic HTML form, its purpose is to gather information from a user. With this information, we can do many things, such as create a basic chat (like what we are doing now). Notice that the “input” and “textarea” tags have the attribute “name” in them, these are very important pieces of information, this is how this form relates to our PHP, and you will see how in just a second. I then have the following code to parse my BBC: $code = preg_split("/(\[code\].+?\[\/code\])/m", $row['content'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); So, my question is, why doesn't it find the two "code" and "/code" tags? It converts it to an array, but there is only one item in the array. Quote Link to comment https://forums.phpfreaks.com/topic/164461-solved-not-finding-my-bbc-tags/ Share on other sites More sharing options...
Garethp Posted July 2, 2009 Share Posted July 2, 2009 Try this instead $Pattern = '/\[.+code\]/is'; $code = preg_split($Pattern, $row['content']); But, if that doesn't work, are you sure you have the right input? Quote Link to comment https://forums.phpfreaks.com/topic/164461-solved-not-finding-my-bbc-tags/#findComment-867582 Share on other sites More sharing options...
nrg_alpha Posted July 2, 2009 Share Posted July 2, 2009 The Little Guy, if I underdstand your post correctly, I think you need to use the s modifier in place of m in your preg line.When I tried that, I got 3 array elements. EDIT - And in the event there is the code bbc tags in caps, you can also add the i modifier. @Garethp, Your code is problematic for a few reasons. The use of .+ is not appropriate here, as in essence, it will only split the string by [/code]. Also, you can have a look at this thread as to why using .* or .+ in general is a bad idea (posts #11 and #14). Those pitfalls might not apply here.. but it's important to note those pitfalls none the less. Quote Link to comment https://forums.phpfreaks.com/topic/164461-solved-not-finding-my-bbc-tags/#findComment-867712 Share on other sites More sharing options...
The Little Guy Posted July 2, 2009 Author Share Posted July 2, 2009 Thanks nrg_alpha! that works! Quote Link to comment https://forums.phpfreaks.com/topic/164461-solved-not-finding-my-bbc-tags/#findComment-867898 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.