Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/164461-solved-not-finding-my-bbc-tags/
Share on other sites

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.

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.