Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> PHP And Texts: Need Help With PHP String Functions
Jens_L
post Nov 25 2005, 09:47 AM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 9
Joined: 24-November 05
Member No.: 9,796



Hey people!

I'm pretty new with PHP and MySQL. I wanna have all the text on my site in MySQL. But i'm having trouble with the inputing from HTML-forms, like <textarea>.

How to i do it?
Can i use PHP or is it better to use javascript and sorta add htmltags into the <textarea> tag?

I wanna make a texteditor where i can use bold, italic and that kinda stuff.

I'm thankful for any help...

/Jens

This post has been edited by miCRoSCoPiC^eaRthLinG: Nov 25 2005, 11:35 AM
Go to the top of the page
 
+Quote Post
Houdini
post Nov 25 2005, 12:46 PM
Post #2


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340



Not really sure about what you are trying to do but I think from your post that you r site will have textareas (which are part of an HTML form) and you want to store the data that is in these areas in a MySQL database. So you need to look at the striptag() PHP function and also the htmlspecialchars() PHP function at the links provided.

You will need to be a little more specific on how you are going to set up your site for anyone to really help you do what you are wanting to do and learning about PHP will help you out as well as learning some basic MySQL queries, it sounds like you are starting from the word go.
Go to the top of the page
 
+Quote Post
jipman
post Nov 26 2005, 11:42 AM
Post #3


Pretty please?
Group Icon

Group: Members
Posts: 733
Joined: 28-November 04
From: Holland
Member No.: 1,552



Of course not houdini, the guy wants to have a texteditor that can use bold italic and stuff. With stripping tags you lose the markup information in the text.

Anyway, to have a php script take input from a html page with a textarea or textfield. You first need to have a webpage, maybe something like this:

CODE

<html>
<form name="foo" action="post.php" method="post">
<textarea name="txt">
</textarea>
<input type="submit" name="sub" value="Save">


Save this as a regular html file.

Now you need a script named post.php that does someting with the information.

CODE

<?php

//this line reads the information that was send by the html file
$txt = $_POST['txt'];

// Now you need something that connects to a database and saves it
// But since that's too much work, I'm gonna show that this works
// and print the information on the scree

echo($txt);
?>


If you wanna save things in a database, check the php.net reference pages

http://nl3.php.net/manual/en/ref.mysql.php

Good luck with it.
Go to the top of the page
 
+Quote Post
Jens_L
post Nov 28 2005, 10:27 PM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 9
Joined: 24-November 05
Member No.: 9,796



Thanks!
I know how to use php to store stuff in MySQL my problem is when i SELECT it and post it on my page. I don't seem to get all the newlines and stuff if i don't write html like <p></p> in the <textarea> tag.

I wanna do something like this texteditor i'm using right now

Thanks for ur help!

Go to the top of the page
 
+Quote Post
Houdini
post Nov 29 2005, 01:59 AM
Post #5


Super Member
Group Icon

Group: Members
Posts: 572
Joined: 25-April 05
From: Nashville Tennessee
Member No.: 4,340



First you would have to have a PHP that first takes the entered text that it can look at and render back in HTML, because this is what browsers use to convey the content of a page, since usually a text area would only produce the text as written to it ver batim then HTML tags or PHP code are meaningless.

So you would have to take the text entered into the text box and then running it through a parser of some sort and in this case you would use preg_replace and or str_replace that would be undestood by another script to render what you desire.

In the case of the Invision when you click one of the buttons like B I U it passes through the file in Invision board through 1.3.1 the source/post_parser.php file which would in turn parse the text and using preg_replace it would turn the BB or IB Code and turn it into HTML so that those viewing it would see the intended formatting. Below is an example of how this is done with just one simple tag like the bold tag.

CODE
$txt = preg_replace( "#\[b\](.+?)\[/b\]#is", "<b>\\1</b>", $txt );


then you have to do a couple of more things with this text after converting to HTML for display, this is when you want to edit the entered text that is in the database back to the origional BB Code or IB Code like so:

CODE
$txt = preg_replace( "#<b>(.+?)</b>#is"  , "\[b\]\\1\[/b\]"  , $txt );


Basically what you see above is code that allows PHP to parse some text and when it sees the bold tag both opening and closing it converts it to HTML so that a borwser will replace it with <b> then whatever is in between it and the </b> that it used the preg_replace() function and displays the intended result in the post.

Does this make any sense to you if not then I would be glad to help you with it but there are already gorum software programs that do this, phpBB does this a little differently and is harder to deal with, making it work with Invision is simple but with phpBB it takes some doing.
Go to the top of the page
 
+Quote Post
vujsa
post Nov 29 2005, 04:26 AM
Post #6


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714
myCENTs:35.43



So basically, you are trying to write a Bulletin Board Code Parser.

You want to have buttons that when clicked will transform the seleced text into the proper BBC to display as bold italic or underlined.

If you are outputing to a textbox, then after each line, you'll need to use the new line code \n

If you are outputting to the HTML body, you'll need to use the non-breaking space code &nbsp;

That will get your line spacing correct. Otherwise everything will show on one line and wrap around to the next.

Now in your script, you'll need to use a switch to change between /n and &nbsp; depending on whether or not you are outputting to a textbox or the the document body.




Now the parser creation that has been explained works like most forum BBC. It changes the
CODE
[b]Whatever[/b]
to
CODE
<b>Whatever</b>


That is all it does. You type the BBC in the textbox and the correct HTML is then displayed in the body.

The data is stored in the BBC form and parsed every time it is displayed in the document body.




This doesn't explain how to create the required buttons and links for your users to simply click on to surround the selected text a with the correct BBC.

For that, you need to use JavaScript.
This JavaScript would change all of the text in this forums post reply box to red.
CODE

java script: window.document.REPLIER.Post.value='[color=red]'+window.document.REPLIER.Post.value+'[/color]';window.stop();

Just type that into the address area of your browser and the text will be coded to red or create a link with this command:
CODE

<a href="java script: window.document.REPLIER.Post.value='[color=red]'+window.document.REPLIER.Post.value+'[/color]';window.stop();">Red</a>

Clicking on this link on a page with such a textbox would code the text in the textbox for the color red.

Instead of applying the BBC to all of the text in the textbox, you'll want to write a JavaScript link that will only encode the selected text.

I'm not going in to how this is all done, that would be better suited for the Javacript Forum instead.

I hope this begins to answer this rather general question that you have asked.

vujsa
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Php : Variables Included Dont Work In Functions(4)
  2. Google Adsense's Functions(1)
  3. Calling Of Functions Between Mulitple External Javascript Files(2)
  4. VBScript: Help, Looping Through Registry Keys(1)
  5. C++: Basic Classes(5)
  6. Writing Functions In PHP(6)
  7. Php String To Int Typecasting(6)
  8. How To Remove Query String Using Regular Expressions(4)
  9. Javascript Show / Hide Functions(3)
  10. Help Spliting A String Into 3 Variables In C++(2)
  11. Sorting A String Vector(0)
  12. Php Any Variable In String.(1)
  13. C# Tutorial : Lesson 8 - Functions/methods(0)
  14. Check For Occurence Of Substring In String(3)
  15. [photoshop] Make A Wave Effect On Your Texts(1)
  1. Strange Ascii Code 22 Character Detected In Connection String(9)
  2. String Theory(9)
  3. Random With Functions?(4)
  4. Creating Dll With Delphi(0)
  5. Using Regular Expressions To Parse Functions(6)
  6. Php: Lesson #3;functions(0)
  7. String Library Functions(4)
  8. Basic C Language, Functions(5)
  9. Time Functions Needed(9)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 02:33 PM