Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP Please Help.


ghost's Avatar
0 0

Hello,

Im quite new to php and am just teaching myself it. I am building a website for myself and some friends to keep there code and files etc on.

What i want to know how to do is when code when it is submitted in an article to the database how can it be output so it is nice and formatted. Like it is on HBH for example?

Of course i have tried google but i am not totaly sure what i should search for.

Any help would be greatly appreciated!

Thanks all.

Relentless.


ghost's Avatar
0 0

PLease just point me in the right direction as to what i need to learn :)

Thank you,

Relentless.


reaper4334's Avatar
Member
0 0

Not 100% sure of what you're asking… but I think….

If you're storing an article somewhere and you want it to be bold and such… shouldn't you parse the article (in the page that's displaying it) for certain things like whichever code tags you want to use, then convert those to their HTML equivilant, and then display that.

I hope I helped, Reaper


ghost's Avatar
0 0

If you want bbcode take a look at bbcode.phps and bbcodes.xml (links may die on occasion).

Edit: linkified urls


ghost's Avatar
0 0

Sweet thank you,

Yes well basicly when you add an article and then go to view the content its just in a nasty block of text with now line breaks or anything. And i have no idea where to start to get it to output text properly. Just like here on hbh.

Thank you!

Relenltess.


reaper4334's Avatar
Member
0 0

Maybe something like:

... your code....
str_replace("{b]","<b>",$string);
str_replace("{/b]","</b>",$string);
... then your code to display it...

Hope I helped, Reaper

EDIT:

That post didn't work because it removed my BBCode examples. I've edited it… using the { instead of [


ghost's Avatar
0 0

Well if you want the line breaks, you can use bbcode, but also have it put a line break at every new line. markup$text = str_replace("\n","<br />",$text;


ghost's Avatar
0 0

Or just nl2br

Edit: Reaper your code fails because it allows people to leave a tag unclosed. Of course you could make workarounds, but I suggest you instead use regular expressions, see the code I linked to in my above post.


reaper4334's Avatar
Member
0 0

Fair enough, I was just guessing really… I don't use PHP… I don't really do web programming…

Reaper


ghost's Avatar
0 0

Thank you all very helpfull! :)

Relentless.