Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




BBCode Parsers And Exporting Text From A DB


I'm currently working on a simple (at least I had hoped) script to pull posts from a single "news" forum from phpbb and importing it on the front page of my site. It works great except for the BBCode issues.

It doesn't keep line breaks (biggest concern) as well as text colors, urls, etc (which was expected).  Talking with a friend, he tells me that I'm going to have to insert some BBCode parser to make things work right.  I have 3 questions regarding this:

1) is that my only answer?

2) should I try to use the phpbb BBCode parser that the forum uses?

3) should I install a custom BBCode parser instead?

I did not want to use a portal because they were just over bloated for what I needed and that was simply the posts from the forum itself w/o all the extras like who's online, last post made on the forums, etc.

Would it just be easier to try to strip down something like EZportal to just the info I need instead of trying to use this custom script?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Remove Bbcode From Text
I have the following code that pulls text and subject from a phpBB database and displays it on the main page of a site. I want to pull the bbcode tags out cause it looks ugly. My question is how would I integrate that in to the code that I have below? Code:

Parsing Text Links And BBCode At The Same Time
I'm not sure if my subject for this is accurate but here is what I'm trying to do:

I want to be able to parse BB sytle code along with regular text links at the same time within the same string.

Here's what I mean...

I have links in a string that can appear in two forms simultaneously:

1) [ url=http://www.abc.com]abc[/url] (without the space of course)
2) http://www.abc.com

Both need to be converted to HTML links of the form <a href="http://www.abc.com">...</a>

I can do each operation on it's own without any problems but trying to differentiate between bbcode and regular text links is giving me some trouble.

I'm currently using the following code for converting links to HTML which works great for my purposes:

$text = eregi_replace("((ht|f)tp://www.|www.)([a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})((/|?)[a-z0-9~#%&/'_+=:?.-]*)*)", "http://www.3", $text);

$text = eregi_replace("((ht|f)tp://)((([a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4}))|(([0-9]{1,3}.){3}([0-9]{1,3})))((/|?)[a-z0-9~#%&'_+=:?.-]*)*)", "<a href="" target="_blank"></a>", $text);

Is there anyway to modify the above code to exclude all links in bbcode?

Exporting From Db To Text File
I have the following sql statement that works from phpmyadmin and from the MySQL command line, but not php. The resultant $sql variable is the following:

$sql=select logrecno, county, sumlev
into outfile "/tmp/census.txt"
fields terminated by ','
lines terminated by ""
from sf1_msageo
where sf1_msageo.county=97 and sf1_msageo.sumlev=140

$result=mysql_query($sql); The query executes, returns no messages, and does not create a file. Any idea as to what I'm doing wrong?

Click Button And Adds To Text Area - Like SMF Bbcode
How can I make buttons to add some things to a text area, like the bbcode for SMF?

How Do Xml Parsers Detect Bad Characters?
2 years ago I asked, on this newsgroup, how to weed out non-UTF-8
characters from my RSS feed. I was told that I could not do so with
certainty, but I could try various tricks that would give me maybe
99%. I notice, however, that XML parsers seem to have 100% certainty
when they find bad characters. Consider the last error that I get from
this validation service:

What PHP code would give me this kind of 100% certainty? It seems to
me that, whatever the XML parsers do to determine a bad character, I
could also do, so as to make sure no such character makes it into my
feed.

Problem With XHTML Parsers With Embedded HTML (e.g. Firefox Et-al)
I've got some code I wrote in PHP that will generate a new argument
string for the browser, but the xhtml parser in Firefox and Opera both
complain about my use of &var=value pairs.

Below is my code that generates the string :

function InvokeURL(url_to_forward_to)
{
try
{
var xfamElem = document.getElementById('xFamily');
var mainform = document.getElementById('mainform');
var new_url = url_to_forward_to + "&variable=" + xfamElem.value;

mainform.action = new_url;
mainform.submit();
}
catch(error)
{
alert("InvokeURL encountered an error :" + error.description);
}
}

This works fine with *many* browsers except the new ones.. With IE on
windows (IE6) and Opera, Firefox all complain, Safari and some older
browsers seem to work OK..

If I change the line with the new_url variable setting on it to use a
&amp; instead, it passes the XHTML tests but no longer works at all.. When
using the &amp; it still has that in the URL that shows in the address
bar and hence it seems to cause the script on the other end a lot of
problems as it is unable to properly parse the URL string.

Any ideas on how to portably get around this problem with embedded &
created URL's?

BbCode
Can anyone recommend a simple way of implementing bbcode into a php-based website/database design? I'd like the user to be able to enter the data using bbcode's options (simple click and format options without having to know anything about code... like this site has) and have this display in pages when the results are pulled out of the database and displayed in HTML format.

BBCode
how to make BBC which will disable any code parsing (BBCode, HTML - to display both without parsing it) and tell me, which font to use with it?

Bbcode Help
This is my first time doing bbcode so I'm not really sure how to do this.  I copied this from a tutorial but it doesn't work.

$string = "I am so [b]cool[/b] ";
$bb-replace = array('[b]','[/b]','[i]',[/i]');
$bb-replacements = array ('<b>','</b>','</i>','</i>');
$string = str_replace($bb-replace,$bb-replacements,$string);

The error is a syntax error unexpected T_ARRAY.

BBcode
I making a forum and want to add BBcode to it. How can i do this? I have looked everywhere?

BBCode
I'm creating a small web app in PHP/MySQL and I'm building the backend. At the moment when one of my novice users enter some news via the form it enters it as a text string into the database.

However I need that string styled and as my users are experienced with BBCode I thought they might as well be able to use that.

So what I need is for their BBCode to be converted to HTML attributes either when it's being added to the db or when it's being displayed.

I can find plenty of scripts, but as I'm a bit of a rookie - I need some installation instructions too!

Has anybody dealt with bbCode in your apps before?
Does anybody have any ideas?

Implementing BBCODE?
I have been working on a system to add news and articles to a site, I have the core adding and removing out of the way and have had some very good advice from eelixduppy, the code for what i currently have is at the end of this post.

What i would to acheive is something where if i typed:

HELLO and wanted to make it bold i could wrap HELLO in something like the BBCODE on this forum. for example square brackets with a B inside to start the Bold area and square brackets with a /B inside to close the bold area, I would like to know how i can underline things with this too and perhaps add things such as font colours etc. a basic intro into how to get it to work would be great, here is the code i currently have if it helps in anyway at all.

<?php
include 'dbconnect.php'
$title = $_POST['title'];
$news = $_POST['news'];
$pattern = "/(http://[w.]+)/";
$replace = "<a href='$1'>$1</a>";
$title = preg_replace($pattern, $replace, $title);
$news = preg_replace($pattern, $replace, $news);
$title = mysql_real_escape_string($title);
$news = mysql_real_escape_string(nl2br($news));
$date = date("D d M Y, g:i a");
$sqlquery = "INSERT INTO tnews (Title, Body, Date) VALUES ('$title','$news','$date')";
header("Location: display.php");
//print $sqlquery;
$results = mysql_query($sqlquery);
mysql_close($dbc);
?>

Help With My Bbcode Function
Someone here very kindly gave me a small example of how to implement a bbcode function, I have expanded this function so it now looks like this.

bbcode.php

<?
function bb2html($text)
{
$trans = array("" => '<b>', "" => '</b>',
"[u]" => '<u>', "[/u]" => '</u>',
"" => '<i>', "" => '</i>',
":-)" => '<img src="../images/smile.gif" title="smile :-)">',
";-)" => '<img src="../images/wink.gif" title="wink ;-)">',
"->" => '<img src="../images/arrow.gif" title="arrow">',
">-)" => '<img src="../images/badfrin.gif" title="bad grin">',
":-D" => '<img src="../images/biggrin.gif" title="big grin">',
":-S" => '<img src="../images/confused.gif" title="confused">',
"0-)" => '<img src="../images/cool.gif" title="cool">',
";-(" => '<img src="../images/cry.gif" title="cry">',
"/-¦" => '<img src="../images/doubt.gif" title="doubt">',
":-@" => '<img src="../images/evil.gif" title="evil">',
"<!>" => '<img src="../images/exclaim.gif" title="exlamation">',
"<i>" => '<img src="../images/idea.gif" title="idea">',
"<lol>" => '<img src="../images/arrow.gif" title="lol">',
">-<" => '<img src="../images/mad.gif" title="mad">',
":-¦" => '<img src="../images/neutral.gif" title="nuetral">',
"<?>" => '<img src="../images/question.gif" title="question">',
":-P" => '<img src="../images/raz.gif" title="raz">',
"$-¦" => '<img src="../images/redface.gif" title="red face">',
"8-¦" => '<img src="../images/rolleys.gif" title="rolly eyes">',
":-(" => '<img src="../images/sad.gif" title="sad">',
">-O" => '<img src="../images/shock.gif" title="shock">',
":-O" => '<img src="../images/suprised.gif" title="suprised">',
" " => '<table bgcolor='#cccccc'><tr><td style='border: solid 1px #000000'>', " " => '</td></tr></table>');

$translated = strtr($text, $trans);
return $translated;
}
?>


I do however have a small problem this works fine first time when I add the data to the database, I am using the following code to add the data to the database

newsadd.php

<?php
include '/home/www/juttuffi/auth.php'
include '/home/www/juttuffi/dbc.php'
include '/home/www/juttuffi/news/admin/bbcode.php'

$pattern = "/(http://[w.]+)/";
$replace = "<a href='$1'>$1</a>";

$title = $_POST['title'];
$news = $_POST['news'];

if (!empty($title) &&!empty($news))
{
$title = preg_replace($pattern, $replace, $title);
$news = preg_replace($pattern, $replace, $news);

$title = bb2html($title);
$news = bb2html($news);

$title = mysql_real_escape_string($title);
$news = mysql_real_escape_string(nl2br($news));
$date = date("D d M Y, g:i a");

$sqlquery = "INSERT INTO tnews (title, body, date) VALUES ('$title','$news','$date')";

header("Location: index.php");

//print $sqlquery;
$results = mysql_query($sqlquery);
}
else
{
include '/home/www/juttuffi/header.php'
echo '<san class="notice">'
echo '***ERROR: Please make sure you have entered a title and some news***'
echo '</span>'
echo '<br>'
include '/home/www/juttuffi/news/admin/newsaddform.php'
}

mysql_close($dbc);
?>


This works fine the smilies appear fine in the output, however when i use my edit script which is below i get some distorted output, here is my edit script.

newsedit.php

<?php
include '/home/www/juttuffi/auth.php'
include '/home/www/juttuffi/dbc.php'
include '/home/www/juttuffi/news/admin/bbcode.php'

$pattern = "/(http://[w.]+)/";
$replace = "<a href='$1'>$1</a>";

$title = $_POST['title'];
$news = $_POST['news'];
$id = (int)$_POST["id"];

if (!empty($title) &&!empty($news))
{
$title = preg_replace($pattern, $replace, $title);
$news = preg_replace($pattern, $replace, $news);

$title = bb2html($title);
$news = bb2html($news);

$title = mysql_real_escape_string($title);
$news = mysql_real_escape_string(nl2br($news));

$sqlquery = "UPDATE tnews SET title='$title', body='$news' WHERE id='$id'";

header("Location: index.php");

//print $sqlquery;
$results = mysql_query($sqlquery);
}
else
{
include '/home/www/juttuffi/header.php'
echo '<span class="notice">'
echo '***ERROR: Please make sure that yu have not tried to submit any empty fields***'
echo '</span>'
echo '<br>'
include '/home/www/juttuffi/news/admin/newseditform.php'
}

mysql_close($dbc);

?>


as you can see the edit code is almost identical to the add code, however say i added a simple news post which contained one smiley.

:-), this would appear as a smiley fine but then say i edited the post and didn't change anything but just clicked "edit" you would expect there to be no change in the output and for it to remain a smiley

:-)

instead i get something like this after editing

:-)">

can anyone help me locate the problem here and perhaps tell me how to solve it, I would be extremely grateful.

Strip Bbcode
I've been trying to piece together a function that can strip bbcode/vBcode from a block of text (ie: posts). I don't want to translate any of it - just remove all instances of [ ] and whatever tags are between them. This is probably a simple string parsing application, but I can't seem to figure out a way to pull it off.

Bbcode Interface
I'm implementing a bbcode parsing engine on a news script, but my only concern is how to create those buttons that interact with the textbox and automatically insert tags and such when you click on them.

Parsing (BBCode)
I'm trying to make a BBCode parser for a forum project I'm working on. I've got the whole bit that finds the code and says turn [b] -> <strong> and that, but my problem is, if you put [b]text, the rest of the page is in bold. What I want is it to automatically add the closing tag. How do I do this?

Youtube BBcode
i want to add a youtube bbcode to my online game to allow players to embed youtube into their profiles using [youtube]video id[/youtube]

so i need to convert this to work as the above bbcode

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/YEfKdjOjqso"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/YEfKdjOjqso" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

thats just a example embed. ive tried several different ways of doing this, any ideas?

Bbcode Parser
Im currently looking for a php script that i can use that will allow me to parse data from my sql database into a safe output. I have searched around and found basic ones, such as text formatting, but what I require is a way to provide images, flash, music etc WHILE sanatising the data to get rid of security holes (XSS or what ever it is).

Does anyone know where I can obtain one? (I could try to code one myself, but my current time is limited )

Regex BBCode Code
I've got my forum system setup so you can use BBCode [url ] etc....... but if the user doesn't put [url ] a round a hyperlink i want when the message is posted to add the [url ] around it if not already there.

Replacing Bbcode With Html Tags Using Php
i have a place for people to post with bbcode (written with javascript), the data is posted and sent to a mysql database, and retrieved from my website's page, where it is displayed.

when the data shows up on the page, the bbcode is still visible. is there a php script for this? if there is where would i put it? on the website's page?

BBcode, Forms And Database Security
I have a form where the user can enter some BBcode to style text but I am really concerned about database security.

When I submit a form, I use stripslashes to get rid of the crap before it enters the database but will this affect the BBcode as it has a slash i.e. [/tag]

What is the best way so i can insert the BBcode or the converted HTML into my database without compromising my database?

Removing The Bbcode_id From Bbcode Tags
phpbb, at least, puts a unique ID number into each bbcode tag a user posts, for example, if I were to post bold text and look at the raw code in the database, it would look like this:

[b:9f0e836e4c]bold text[/b:9f0e836e4c]

Now, it's simple enough to remove those numbers using this regex:

[b:[^]]+]

What's really got me stumped, though, is how to do this when the bbcode has attributes, such as size and a quote: Code:

CSV Exporting
I created the csv file, but it only shows the last record in my db. How can I make it show all of the records? Here's the code:

Exporting A Database
developed a php project using mysql as the database.i work on a win-nt machine....how do i export my database to the host server which runs linux???

Exporting To An XML File
I grabbed a web page and had it extract only the links between certain line numbers. Now I want to take that output and export it to an XML file in a format of my choosing. For example:

<a href="mysite.com">This is my site</a>

Would export to:

<link>mysite.com</link>
<description>
This is my site
</description>

I will then take that XML file and output it as HTML, however I already have this bit accomplished.

PHP Exporting To Quickbooks
I am working on a web-based payroll application (PHP/MySQL of course) that needs to be able to dump each employee's information in to a Quickbooks formatted file for payroll processing.

I have done this several times exporting to a tab/comma deliminated text file (usually MS Excel), but I was wondering if anyone could see any reason why it could not be done the same way (assuming that Quickbooks uses a a tab/comma file structure) for Quickbooks??? If it can be done would I use the same mechanics as I would for Excel (changing the file type meta tag)?

Database Exporting
Quite by accident, I found the mysqldump utility, that comes with MySQL,
which dumps/backsup a database, table, or record. It looks very versatile!

Does PHP have a way to export records of a MySQL database? Anything that
does the same independent of the database used?

Database Exporting
As part of the CMS that I've written, I would like to give users the ability
to backup their own databases. Is there any way that this can be done with
PHP? What I'd like is for them to click a link and for it to create a txt
file and open the "Save as" dialog box so that they can save it off to their
hard drive.

Exporting Csv File
I'm having issues getting all the information from 3-4 databases into one
csv file.. What easy thing am I missing this time?

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=export.csv");
header("Pragma: no-cache");
header("Expires: 0");
$select = "SELECT * FROM ordersCopy O, orders_products P, orders_total Q
WHERE O.orders_id=P.orders_id OR O.orders_id=Q.orders_id AND
orders_status=&#393;'";

$export = mysql_query($select);
$count = mysql_num_fields($export);
for ($i = 0; $i < $count; $i++) {
$header .= mysql_field_name($export, $i)." ";
}
while($row = mysql_fetch_row($export)) {
$line = ''
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = " ";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . " ";
}
$line .= $value;
}
$data .= trim($line)."
";
}
$data = str_replace("
", "", $data);
if ($data == "") {
$data = "
(0) Records Found!
";
}
print "$header
$data";

Exporting Mysql
there is a function in phpmyadmin that exports all the data etc from a mysql
database to an sql text document, or Excel File.

I would like to know if there is an inherent way of doing this without
phpmyadmin. - straight through php.

Exporting From MySQL To .csv Using PHP
I'm sort of new to PHP. I am using the following code to retrieve a
column from a database and to put all of the results into a .csv
file. This allows creates a .csv file, but only lists the first
result from the database. It is not returning all of the rows. I
know the issue is somewhere in my "foreach" but I'm not sure where.

<?php

$selectSql = "SELECT artist_name FROM lounge_products";
$selects = $db->getAll($selectSql);

foreach($selects as $select) {

$content = $select[artist_name].",";

}

Header("Content-Disposition: attachment; filename=export.csv");
print $content;
?>

Exporting To Excel
I followed the really cool how to at http://www.phpfreaks.com/tutorials/114/0.php but I had to change some things to get it to stop giving me errors. After I did that It seemed to work great but it put everything into one cell in the excel document. Code:

Exporting MySQL Table
Hi,

How do you export a MySQL table to a tab-delimited text file so I can put it into excel?

Exporting To Microsoft Access
I have a PHP website with a mySQL database and a client wants to be able to see the database on his computer using Microsoft Access.

I would like to be able to make a special backdoor section for him, where he enters his username and password and is given a link which will make take a snapshot of the mySQL database and convert it to a Microsoft Access database which he can download to his computer.

Is this possible?

Since he isn't very computer savvy I need a way as user friendly as possible to let him download the database and view on his local computer.

Exporting Mysql To Csv Or Excel Via PHP
Hi, I need to know how to write a php code how to export the mysql database into CSV or Excel or ISO 20001 format. or if you know any tutorial site for it.

Exporting Data To MS Excel
How to export data to xls file using PHP? Is it possible to edit a
look of document (like cell size, borders etc.) ?

File Exporting To Excel
This code exports data from my DB into an Excel file by using " " as the delimiter. It runs through the script over and over until it's done creating an Excel file with columns of data, but is there a way that I can add a value to the beginning of the script - thereby naming the columns? Code:

New Exporting / Getting News From Different Server
Which is the best way to fetch news from my server and display it on other sites. I have an admincp i would like to display announcements in from my site. Maybe just some how remotly including a file from my server or something.

Exporting MySQL Database To File Using PHP
I want to export my database to a file that is hosted on the same server. I got this script from somewhere, but it doesnt work. Most likely because I cannot access mysql command thru the shell_exec() command, however, I am able to use the wget command thru the shell...

Here's the code I was trying to use:

Exporting Search Results To A CSV File
I am about to start programming up a database, where the client requies the data exported to a CSV file for use in mail merge documents etc.

What I would like to know is, if they run a query on the database, and only export five of the 10 fields in the table to the list, how would I go about reatining the field names on the first line of the CSV file?

Exporting Mysql Data To CSV In Php Code!!
how can i export the results of a query to a csv file with the columns name in the filed name of the csv???suppose USERID is the 1st column the USERID should be named in A in CSV while its data is under of it??is it possible?

Exporting Information From Entourage To A Website.
I have this new website for a client, it has a calender which shows events from a mysql database but they don't want to have to update the information to it manually.
What they are using is a program called Microsoft Entourage. What are the possible ways for me to be able to get that information every 1 hour and get it into a database?

Problems While Exporting Data Using Pipe Symbols
I am facing problems while trying to export data into
pipe format. In fact I am fetching records from mysql database and then
trying to create a text file ( using pipe as delimeter) , intending to
open in Excel.

The data is been inserted from textarea fields, where the
user can write text and may press enter key to format his text
accordingly. Now when the data entered into the database it keeps some
unidentified value so as to keep the formatting. Hence while displaying
the text file I find that lines are seperated according to the format
user gave. Thus creating the problem while opening up in the excel
file.

example:

Exporting Database To Excel (via Website, NOT PhpMyAdmin)?
I know via phpMyAdmin I can export my database in Microsoft Excel 2000 format, and can check a box to 'Create field names as first row', but it doesn't give me the php code used to achieve this. I need to have a page on a website so the administrators will be able to do this for themselves, does anyone know if this is possible?

Exporting Data From Mysql Using Php In Excel Form..?
I have a table in mysql wich contain a sim_number field which is 19 digit unsigned number. i have designed a script using php headear command for exporting data as excel. It is working but with the follwoing problem.
Since sim_number is 19 digit number when it get exported as .xls file. now when that .xls file is opened, excel automatically detect this sim_number as number and , since excel can store only 15 digit in number format it converts its last 4 digits to zeros.

Is there any way to get this sim_number exported as text so that excel store complete 19 digit number in text format. I cannot attach some charctor to this sim_number because of restricion on file format.

Exporting DB Results (or Flat File) To An Excel File
I have two scripts, neither of which have been written, that will need to collect user information. They will either write to a flat file or to a MySQL DB, and I need a way for an administrator to grab an Excel file based on this data.

First, no more than 100 people are expected to sign up, so flat file is certainly viable. Do you recommend I use DB or flat file?

Second, based on your recommendation, how should I go about exporting the user data to an Excel file? There will be about ten form fields per registration to give you an idea.

Quickly Adding Text To A Mysql Text Field That Is NOT Empty
Is there a way to insert text into a mysql text field that already has
text into it; without having first to extract the existing data and
append the new text to that string variable and then insert the new
string.

Basically i'm looking for a way to do it with a single query not 2 (one
being a select to gather existing data).

Gaining Access To How MySql Parses Text For Full Text
I want to gain access to the function or process MySql uses to parse words and phrases for Full Text searching. Here is an example.

If the user inputs...

Milan in history

MySql will search for milan, history, and milan history. Is there a way to extract just the combination of terms MySql uses to search the db without the stop words? Stop words are automatically eliminated from the search request unless the user encloses a phrase in quotes.

What I am trying to do is develop a script to highlight found search terms and phrases. I can explode a phrase into single words but if I do that the stop words would be included in the array. If there is some way of getting into the parsed words or phrases MySql Full Text actually uses to search, I can use each of those combinations as a keyword in my highlighting script.

This request is about searching for the code or any code related to the questions involved.

Text Area Not Accepting Large Amounts Of Text
I have a form where teachers enter homework assignments and they are then stored in a MYSQL database and retrieved elsewhere.

I have been using "get" with the form. The code is simple:

<textarea name="array[assignment]" cols="60" rows="10" id="array[assignment]"></textarea>

It does allow post of 100 words, etc. Stuff that teachers normally submit.

What's happening is that it won't allow very large posts (over 300 words maybe? ) Not sure what the cut off is. When you press submit it won't go, or there is an error where it won't submit.

Is there a limit for text fields? Since the fields scroll, I didn't think that having only 60 rows was any type of real limit, I though you could put in as much as needed. But then all of it ends up in the address bar, so there must be a limit of some sort.


Copyright © 2005-08 www.BigResource.com, All rights reserved