phpBB

Development Wiki

Difference between revisions of "Tutorial.Parsing text"

From phpBB Development Wiki

Line 10: Line 10:
 
generate_text_for_storage ($text, $uid, $bitfield, $flags, $allow_bbcode, $allow_urls, $allow_smilies);
 
generate_text_for_storage ($text, $uid, $bitfield, $flags, $allow_bbcode, $allow_urls, $allow_smilies);
  
$sql = 'INSERT INTO ' . YOUR_TABLE . " (text, bbcode_uid, bbcode_bitfield) VALUES ('$text', '$uid', '$bitfield')";
+
$sql = 'INSERT INTO ' . YOUR_TABLE . " (text, bbcode_uid, bbcode_bitfield, bbcode_flags) VALUES ('" . $db->sql_escape($text) . "', '" . $db->sql_escape($uid) . "', '" . $db->sql_escape($bitfield) . "', $flags)";
 
$db->sql_query($sql);
 
$db->sql_query($sql);
 
</php>
 
</php>
 +
 +
text should be a TEXT column, bbcode_uid and bbcode_bitfield should be VARCHARs and bbcode_flags should be an INT column.
  
 
=== Displaying text downloaded from DB ===
 
=== Displaying text downloaded from DB ===
 
<php>
 
<php>
$sql = 'SELECT text, bbcode_uid, bbcode_bitfield FROM ' . YOUR_TABLE;
+
$sql = 'SELECT text, bbcode_uid, bbcode_bitfield, bbcode_flags FROM ' . YOUR_TABLE;
 
$db->sql_query($sql);
 
$db->sql_query($sql);
  
$allow_bbcode = $allow_urls = $allow_smilies = true;
+
$text = generate_text_for_display($row['text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_flags']);
 
+
$flags = (($allow_bbcode) ? 1 : 0) + (($allow_smilies) ? 2 : 0) + (($allow_urls) ? 4 : 0);
+
$text = generate_text_for_display($row['text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $flags);
+
  
 
echo $text;
 
echo $text;

Revision as of 02:16, 7 January 2007

Parsing text with BBCodes, smilies etc.

Inserting text to the DB

$text "bla bla bla"// will be modified by generate_text_for_storage
$uid $bitfield $flags ''// will be modified by generate_text_for_storage

$allow_bbcode $allow_urls $allow_smilies true// false is default for generate_text_for_storage function

generate_text_for_storage ($text$uid$bitfield$flags$allow_bbcode$allow_urls$allow_smilies);

$sql 'INSERT INTO ' YOUR_TABLE " (text, bbcode_uid, bbcode_bitfield, bbcode_flags) VALUES ('" $db->sql_escape($text) . "', '" $db->sql_escape($uid) . "', '" $db->sql_escape($bitfield) . "', $flags)";
$db->sql_query($sql);

text should be a TEXT column, bbcode_uid and bbcode_bitfield should be VARCHARs and bbcode_flags should be an INT column.

Displaying text downloaded from DB

$sql 'SELECT text, bbcode_uid, bbcode_bitfield, bbcode_flags FROM ' YOUR_TABLE;
$db->sql_query($sql);

$text generate_text_for_display($row['text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_flags']);

echo 
$text;

Generating text for editing

$sql 'SELECT text, bbcode_uid FROM ' YOUR_TABLE;
$db->sql_query($sql);

decode_message($row['text'], $row['bbcode_uid']);

echo 
$row;