help for beginner

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asterix040173
Forum Newbie
Posts: 3
Joined: Mon Mar 21, 2011 11:34 pm

help for beginner

Post by asterix040173 »

I am trying to display on a php page the data input in a text area .
on each line that the user insert into that text area i want 2 variable (tags) added to the user input.

Let me show you an example...

user input = john
after submit = [player]john[/player]

here is the code that i have done so far...
(my index file):

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>.
        <FORM action="bbcode.php" method="post">
   <P>
   <TEXTAREA name="name" rows="20" cols="80">
   
   </TEXTAREA>
   <INPUT type="submit" value="Send"><INPUT type="reset">
   </P>
</FORM>

        
    </body>
</html>
then my bbcode.php file:

Code: Select all

<?php

$tag1 = "[player]";
$tag2 ="[/player]";
$_post=["name"];
 echo $tag1;
echo $_post;

echo $tag2;


?>

of course later when this will be working, the input will be chosen from online database.


so far the code is not working as the input is not include between the 2 variable tag1 and tag2(it worked with a html form single line)

any sugestion?

thanks in advance
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: help for beginner

Post by Christopher »

Try:

Code: Select all

$name = $_POST['name'];
echo "$tag1$name$tag2";
(#10850)
asterix040173
Forum Newbie
Posts: 3
Joined: Mon Mar 21, 2011 11:34 pm

Re: help for beginner

Post by asterix040173 »

thanks.... i did find this:)

could you tell me now, how to do if there is multiple line

example:

john
david
estelle

to get output like this:
[player]john[/player]
[player]david[/player]
[player]estelle[/player]

i will of course look by myself
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: help for beginner

Post by Christopher »

Use explode() to split the line on returns. That will convert "john\ndavid\nestelle" to array('john', 'david', 'estelle').
(#10850)
asterix040173
Forum Newbie
Posts: 3
Joined: Mon Mar 21, 2011 11:34 pm

Re: help for beginner

Post by asterix040173 »

i have looked this function,but it a bit complicated for me...
could you show me a code example?
Post Reply