|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Forms Help Please.....BEN or anyone that can do it!
Help please.
Not sure were to start So I will dive in and hope this makes sence so someone can help me. Basicly what I want to be able to do is what this form is doing now. If I add a link or an email it will convert it into html when viewed. Also I just pressed enter 2 times and now their are spaces on line between the word viewed and also. How do I convert what my user is typing into their news or post field to convert to html? If this is 2 hard all I would be happy with is allowing a person to use an option like below on Show Signature. I guess I have to start somewhere!!!
__________________
Thanks, Attila http://www.glorynaspiration.com http://www.abitofthings.com |
|
#2
|
|||
|
|||
|
Quote:
Firstly, ill do this problem first as it is simpler When you hit enter in a textarea, it actaully stores that "enter" character as either \n or \r\n (depends on your server) Now html does not entrypriate this as a new line in the browser, so it displays it on the same line, however there is a function in php that will take the \n or \r\n and convert that into html: nl2br(); so say if you hit your submit button, on the next page you would do something like this $data = nl2br($_POST['textarea_name']); If you then echo out $data, it will show it with the line breaks. The <br> tags are xhtml complient, so they will be like <br /> Now for your other problem, this will require regular expressions. However because ive have no experience with them (im lazy i know) i wouldnt know how to do that, so maybe someone else knows of a method. |
|
#3
|
|||
|
|||
|
Quote:
Simply done using preg_replace(). You could also use str_replace(), but not as featurefull as preg. The only thing you are doing is replacing [site]*****************[/site] tags with HTML equivelents - [site] -> <a href="***"> [/site] -> </a>, and so on. preg_replace() provides more features for this, so I would recommend using that instead of str_replace(). Text colors are also done in the same way. You would match a [col=green]**********[/col] with HTML -> [col-green] would be -> <span style="color: rgb(51, 204, 0);"> [/col] would be -> </span> Same way with text formatting, smilies, and so on... Ben has you covered with nl2br()...
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
|
#4
|
|||
|
|||
|
Thank you this is helping....Now another question...Think it is Javascript....
I know how to do the pop up window when you click in httP:// upove but how do you get it to enter it into the line of text you are working on? If you know how to do the javascript please share that as well. |
|
#5
|
|||
|
|||
|
Ok, here you go. I wrote this up for you to use. The link format will be ->
Code:
[LINK]http://www.link.com[NAME]Link[/NAME]http://www.link.com[/LINK] That format should be very easy to do preg_replace() on. Here is the complete HTML page with the JavaScript in the <head> Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function passText(passedvalue) {
oldvalue = "";
if (passedvalue != "") {
var totalvalue = passedvalue+oldvalue;
document.postform.post_body.value = totalvalue;
oldvalue = document.postform.post_body.value;
}
}
function jsPrompt() {
var answer = prompt("Please type the name of your link below", "");
if (answer) {
a = "[NAME]";
b = "[/NAME]";
var totalvalue = a+answer+b;
jsPromptTwo(totalvalue)
}
}
function jsPromptTwo(namevalue) {
var answer = prompt("To add a link to a webpage, fill out the field below.","http://www.");
if (answer) {
c = "[LINK]";
d = "[/LINK]";
oldvalue = document.postform.post_body.value;
var totalvalue = oldvalue+c+answer+namevalue+answer+d;
document.postform.post_body.value = totalvalue;
}
}
</script>
</head>
<!-- CONTENT -->
<body>
<form name="postform" method="" action="">
<input type="button" name="button" value="add text" onClick="jsPrompt()">
<br><br>
<textarea name="post_body" cols="50" rows="10"></textarea>
</form>
</body>
<!-- END CONTENT -->
</html>
Copy and paste the above and open in your browser to see the results... |
|
#6
|
|||
|
|||
|
Thank you so much for all the help....Hopefully one last question.
How do I use PHP Code:
I'm thinking like this from your example. PHP Code:
Although I know I am wrong it is not working. Thanks again I apreciate it alot ![]() |
|
#7
|
|||
|
|||
|
Ok Attila - you caught me on a good day. First, made an adjustment to the JavaScript I previously posted to make the string parsing easier. So, replace the JavaScript from earlier with the JavaScript shown below ->
Code:
<script language="JavaScript" type="text/JavaScript">
function passText(passedvalue) {
oldvalue = "";
if (passedvalue != "") {
var totalvalue = passedvalue+oldvalue;
document.postform.post_body.value = totalvalue;
oldvalue = document.postform.post_body.value;
}
}
function jsPrompt() {
var answer = prompt("Please type the name of your link below", "");
if (answer) {
a = "[NAME]";
var totalvalue = a+answer;
jsPromptTwo(totalvalue)
}
}
function jsPromptTwo(namevalue) {
var answer = prompt("Type the address (or url) below","http://www.");
if (answer) {
c = "[LINK]";
d = "[/LINK]";
oldvalue = document.postform.post_body.value;
var totalvalue = oldvalue+c+answer+namevalue+d;
document.postform.post_body.value = totalvalue;
}
}
Now, below is a function to do the replacement in the feeded text -> PHP Code:
Now, to use, just follow as the example as in the code above. Use your posted text or whatever and feed it to the function for parsing... EDIT:: Do not use cut and paste for php above, use the attachment. VB stripped some of the slashes in the above.... |
|
#8
|
|||
|
|||
|
Thanks alot jpenn you have helped tremendously...(Sp)
I am up for work will look at it when I get home and get back with you I testid it realy quick....Nice work. Thanks once again I am ![]() |
|
#9
|
|||
|
|||
|
Ok thank you once again for all the help...
Ben I am sorry for posting this here I just did not want to break up the postings to the javascript area. Since it all goes together jpenn If you are feeling up to it can you break this code down for me piece by piece please. I have gotten it to work with Bold Italic adn the such but have not figured it out. PHP Code:
Can anyone help me with a little more Javascript. I can get the javascript to work like above when you press the B and it brings up a window. But what I would like to do is set it up so when you press the B the B will then turn into B* letting the poster know that they need to close the tag. Further doing would be to have something like the Close Current Tag and a Close all tags..... Can someone please push me in the correct direction. |
|
#10
|
|||
|
|||
|
Not a problem Attila.
Lets look at the expression match pattern -> Code:
$_pat = "/(\[LINK\])(.*?)(\[NAME\])(.*?)(\[\/LINK\])/i"; This pattern says look for [LINK] followed by (anything) then [NAME] followed by (anything) then [/NAME]. The 'i' at the outside the pattern tells it to be case insensative, meaning that [LINK] can be [linK] or [LInk] or any other way; respectivley. If a match is found, it is broken into its parts and held in its componet $scalars. Lets now look at the replacement -> Code:
$_rep = "<a href=\"$2\" target=\"_blank\">$4</a>"; $2 is holding the (.*?), or the first (anything). Same goes for $4. We are now just rebuilding the string by replacing the [LINK] with '<a href=' - then $2 - and so on. |
|
#11
|
|||
|
|||
|
WOW great explination....I now understand.....are these / and \ for escaping the following character???
Also what if I wanted to add 2 strings togetehr how do I do that... PHP Code:
I know the above dosen't work so what is the approprate way to do this? |
|
#12
|
|||
|
|||
|
The begining '/' is the start of the reg expression while the ending '/' is the ending delimeter. The '\' in the expression are escapes.
Now, your code -> PHP Code:
Can be shortened to -> PHP Code:
The . (dot or period) is string concatenation. It is used to add (not add in addition or mathmatics, to piece together strings) strings together. |
|
#13
|
|||
|
|||
|
Thanks so much....If you want to see some of your advice you have given me in work you can go to this website
GnA Squad You will have to register to post any news and see some of your tips and tricks.. I truely appreciate your help! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Forms Help Please.....BEN or anyone that can do it! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|