473,378 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to pick out some text for use in a Forum?

I'm writing an extension for some PHP forum software. $String is the
post contents, and I want to do the following to it. Note that I'm not
looking for someone to solve this for me, I'm just not sure what the
best approach is.

1. Find all instances of
Expand|Select|Wrap|Line Numbers
  1. user post text...
2. If the lang attribute is supplied, keep track of its value for that
code block, e.g. [code lang="css"]
3. Wrap the contents of the code block in HTML tags with the CSS class
set to lang's value if it was specified
4. Of course, output this new string in the same position as before in
the post

Any ideas? Thanks!
Jul 29 '08 #1
5 1380
On Jul 29, 1:10*pm, 703designs <thomasmal...@gmail.comwrote:
I'm writing an extension for some PHP forum software. $String is the
post contents, and I want to do the following to it. Note that I'm not
looking for someone to solve this for me, I'm just not sure what the
best approach is.

1. Find all instances of
Expand|Select|Wrap|Line Numbers
  1. user post text...
2. If the lang attribute is supplied, keep track of its value for that
code block, e.g. [code lang="css"]
3. Wrap the contents of the code block in HTML tags with the CSS class
set to lang's value if it was specified
4. Of course, output this new string in the same position as before in
the post

Any ideas? Thanks!
Note that I don't need to actually output the text (the software
handles that), just return a $String value.
Jul 29 '08 #2
On Jul 29, 1:12*pm, 703designs <thomasmal...@gmail.comwrote:
On Jul 29, 1:10*pm, 703designs <thomasmal...@gmail.comwrote:
I'm writing an extension for some PHP forum software. $String is the
post contents, and I want to do the following to it. Note that I'm not
looking for someone to solve this for me, I'm just not sure what the
best approach is.
1. Find all instances of
Expand|Select|Wrap|Line Numbers
  1. user post text...
2. If the lang attribute is supplied, keep track of its value for that
code block, e.g. [code lang="css"]
3. Wrap the contents of the code block in HTML tags with the CSS class
set to lang's value if it was specified
4. Of course, output this new string in the same position as before in
the post
Any ideas? Thanks!

Note that I don't need to actually output the text (the software
handles that), just return a $String value.
Here's what I've come up with so far. Any recommended changes? It
seems to do the job pretty well.

$hlString = $String;
$hlString = str_replace('<', '&lt;', $hlString);
$hlString = str_replace('>', '&gt;', $hlString);
$hlString = preg_replace("/\[code( lang=\"([A-Za-z]+)\")?\]/", "<pre
name=\"code\" class=\"$2\">", $hlString);
$hlString = str_replace("[/code]", "</pre>", $hlString);
return $hlString;
Jul 29 '08 #3
On Jul 29, 12:10*pm, 703designs <thomasmal...@gmail.comwrote:
I'm writing an extension for some PHP forum software. $String is the
post contents, and I want to do the following to it. Note that I'm not
looking for someone to solve this for me, I'm just not sure what the
best approach is.

1. Find all instances of
Expand|Select|Wrap|Line Numbers
  1. user post text...
2. If the lang attribute is supplied, keep track of its value for that
code block, e.g. [code lang="css"]
3. Wrap the contents of the code block in HTML tags with the CSS class
set to lang's value if it was specified
4. Of course, output this new string in the same position as before in
the post

Any ideas? Thanks!
the best way to do it is to use regular expressions to find the "lang"
as well as any text inside the tags.
Jul 29 '08 #4
On Jul 29, 1:40*pm, gardnern <nat...@factory8.comwrote:
On Jul 29, 12:10*pm, 703designs <thomasmal...@gmail.comwrote:
I'm writing an extension for some PHP forum software. $String is the
post contents, and I want to do the following to it. Note that I'm not
looking for someone to solve this for me, I'm just not sure what the
best approach is.
1. Find all instances of
Expand|Select|Wrap|Line Numbers
  1. user post text...
2. If the lang attribute is supplied, keep track of its value for that
code block, e.g. [code lang="css"]
3. Wrap the contents of the code block in HTML tags with the CSS class
set to lang's value if it was specified
4. Of course, output this new string in the same position as before in
the post
Any ideas? Thanks!

the best way to do it is to use regular expressions to find the "lang"
as well as any text inside the tags.
I forgot to note that I needed to convert < and as well. My little
script works great! CSSForums.org will have syntax highlighting (using
SyntaxHighlighter, see http://code.google.com/p/syntaxhighlighter/)
for HTML, XML, CSS, JavaScript, PHP, and SQL once I finish polishing
this extension and install it this evening.
Jul 29 '08 #5
On Jul 29, 1:53*pm, 703designs <thomasmal...@gmail.comwrote:
On Jul 29, 1:40*pm, gardnern <nat...@factory8.comwrote:
On Jul 29, 12:10*pm, 703designs <thomasmal...@gmail.comwrote:
I'm writing an extension for some PHP forum software. $String is the
post contents, and I want to do the following to it. Note that I'm not
looking for someone to solve this for me, I'm just not sure what the
best approach is.
1. Find all instances of
Expand|Select|Wrap|Line Numbers
  1. user post text...
2. If the lang attribute is supplied, keep track of its value for that
code block, e.g. [code lang="css"]
3. Wrap the contents of the code block in HTML tags with the CSS class
set to lang's value if it was specified
4. Of course, output this new string in the same position as before in
the post
Any ideas? Thanks!
the best way to do it is to use regular expressions to find the "lang"
as well as any text inside the tags.

I forgot to note that I needed to convert < and as well. My little
script works great! CSSForums.org will have syntax highlighting (using
SyntaxHighlighter, seehttp://code.google.com/p/syntaxhighlighter/)
for HTML, XML, CSS, JavaScript, PHP, and SQL once I finish polishing
this extension and install it this evening.
Sadly, I took a step back: My new Parse method doesn't support
converting newlines to <br />. If I use the usual:

$hlString = str_replace("\r\n", "<br />", $hlString);

My syntax highlighter goes haywire and gets <br />s inserted in place
of [code] newlines. How could I apply that replacement without
replacing "\r\n" contained in ? Sounds like another Regex
problem, but these [code] blocks span multiple lines.
Jul 29 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gary Mayor | last post by:
Hi, If I have the ' character within the javascript:pick command it doesn't work. Is there some sort of way of escaping these characters like in server side languages. function pick(symbol) {...
4
by: Chris | last post by:
Hi, I found this code that can solve a problem I have. It sends print direct to printer. Imports System Imports System.Text Imports System.Runtime.InteropServices ...
4
by: kurotsuke | last post by:
Can anybody tell me how I can call the Pick Icon Dialog from C#? I couldn't find any example. Thanks.
4
by: Jerry Camel | last post by:
I'm using a DHTML dialog to present a pick-list to a user. I've got the dialog working using some client side vbscript with a call to window.ShowModalDialog. I can see that the result is being...
4
by: Sam | last post by:
I want to pick some texts in my DataGrid's some cells (not all the cells) in order to show red color. Can you teache me how to do this? Thanks in advance.
8
by: pradeepss | last post by:
Guys, I have a text file which is comma delimited and information. Each information is ended by end of line and started again with comma delimited i.e. 1,2,3,a,4 2,s,4,5,6,7,8,h...
0
Dököll
by: Dököll | last post by:
Continued from: http://www.thescripts.com/forum/thread762010.html -VB 6.0 Professional -Microsoft DAO 3.6 Reference Search Database table... An attempt to fetch data housed in Access:
1
by: blondieUA | last post by:
Hello guys! I have some problem with creating the result page :( I need to create a web-page for my college course in Computer Science. I decided to create a site about Horoscopes. So if a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.