I used SCEditor in my forum. I managed inserting bbcodes to database. But when I try to show codes in the page, bbcodes are shown without styling. No html, no style. Only bad bbcodes. I am investigating for a long time in its documentation pages but I did not find any php parser. Here is the screenshot. Please, could you help me, how do I parse bbcode to html in PHP?
You can use SBBCodeParser. SCEditor and this class were coded by the same person. So it would be more compatible.
Related
What I'm trying to do
I'm trying to use jBBCode to parse and de-parse bbcode into and from html.
The problem
When trying to get the html and turn that back in to bbcode, it just displays html.
Here is the code I'm using to try and switch html back into bbcode.
$parser = new JBBCode\Parser();
$parser->loadDefaultCodes();
$parser->parse($MYHTMLSTRING);
echo $parser->getAsBBCode();
Does anyone know what I'm doing wrong here? I'm sure it's something very simple that I haven't figured out. Any help is appreciated! :D
$parser->parse() takes as input BBCode, not HTML.
After studying the documentation, it is my understanding that this is a one-way parser:
BBCode -> HTML
I believe the design is for you to store the BBCode in your database, and then when it is time to render HTML to visitors, you parse the BBCode at that time.
This way, you are always storing the raw, editable BBCode in the database.
This is a pretty common design-pattern. For example, for applications that use the Markdown Language (instead of BBCode), they typically store raw markdown in the database and only render it to HTML at page-load time.
In Summary:
Store Raw BBCode/Text in your database
when you render a page to a visitor, you do your conversion at that time (to HTML).
$parser->parse($MyBBCode); echo $parser->getAsHTML();
If the user edits the BBCode, save that straight back to DB as BB Code
Documentation Reference
I want to know how i can find the DIV tag in a HTML page. This is because i want to replace the links inside that DIV with different links. I do not understand what exact code i require.
First, notice that PHP won't do anything client side. But you should already know it.
you should use file_get_contents to read the webpage as a string (or what is provided by a library for html parsing).
There is already a question that explain how to parse html in any way: Robust and Mature HTML Parser for PHP
If it doesn't fit your needs, try searching it on google: php html parsing, I found some libraries
For example this library I've found allows you to find all tags: http://simplehtmldom.sourceforge.net/
Notice that this is not a great approach and I suggest you change your html page to be a PHP page, and insert some code in place of A tags. This will make everything easier.
Last thing, if the html page is static (it doesn't change), you can use easily line counting to get contents from X line to Y line, put your customized A-tags and then read from J to the end of file.
Good luck anyway.
I'm facing a problem for a quite long time. Unfortunately I was not able to find the solution by my own, so I have to post my question here.
I am writting a little php script that creates a PDF file from a dynamically created HTML file.
Now I want to "parse" the html file and do a action in addiction to which tag is next in HTML.
E.g.
<div><p>Test</p></div>
My script should recognize:
First tag is a div: do function for div
Second tag is a p: do function for p
I don't know for what I should search. Regular expressions? HTML parser?
Thanks for a hint!
Try an XML parser. In PHP the SimpleXML is probably what you are looking for.
I've used several times phpQuery. That's a nice solution, although it's quite big and seems that is no longer supported (last commit > 10 months).
What you need to do is read the HTML file into a PHP variable/object
http://www.php-mysql-tutorial.com/wikis/php-tutorial/read-html-files-using-php.aspx
And then use RegEx to parse the HTML Tags and Attributes
http://www.codeproject.com/Articles/297056/Most-Important-Regular-Expression-for-parsing-HTML
I can't seem to find a js RTE that will play friendly with snippets of php intertwined in it. I want a mini CMS for the backend of a number of sites. The views have some snippets of php here and there
Are there any RTE's that will leave the php alone, and even show it mixed with the nice formatting?
TinyMCE kills the tags even when entered in html mode and switched back and forth. FCKEdit seems to keep the code intact if pasted into source mode, but it isn't shown in the editing side, so if someone deletes an element with some php in it, bop, it's gone.
And none of the editors like creating nicely indented code, that would be a nice plus as well, but probably over the top to ask, heh.
The Javascript rich text editors make use of the browsers' in-built DesignMode or ContentEditable features in order to implement in-line HTML editing, and these do not support embedded PHP tags.
The solution would have to convert these to some other form, which is not going to get mushed by the browser's HTML editor, then convert them back to PHP tags upon submission.
It could be done. I don't know of any that do, however.
As for creating nicely indented code, it is a similar issue. The browsers munge it in their in-line HTML editors.
I had a similar question a few weeks back:
Textarea that can do syntax highlighting on the fly?
This may be the right thing for you:
http://marijn.haverbeke.nl/codemirror/
They even have mixed PHP and HTML highlighting.
I need some help ... I'm a bit (read total) n00b when it comes to regular expressions, and need some help writing one to find a specific piece of text contained within a specific HTML tag from PHP.
The source string looks like this:
<span lang="en">English Content</span><span lang="fr">French content</span> ... etc ...
I'd like to extract just the text of the element for a specific language.
Can anyone help?
There are plenty of HTML parsers available for PHP. I suggest you check out one of those, (for example: PHP Simple HTML DOM Parser).
Shooting yourself in the foot with trying to read HTML with regex is a lot easier than you think, and a lot harder to avoid than you wish (especially when you don't know regex thoroughly, and your input is not guaranteed to be 100% clean HTML).
(Bad, not working) example which shows why you should not use regex for parsing html.
/<span lang="en">(.*)<\/span>/
Will output:
English Content</span><span lang="fr">French content
More stuff to read:
Parsing: Beyond Regex
For-the-2,295,485th-time-DO-NOT-PARSE-HTML-WITH-REGULAR-EXPRESSIONS
There's this most awesome class that lets you do SQL-like queries on HTML pages. It might be worth a look:
HTML SQL
I've used it a bunch and I love it.
Hope that helps...