PHP - Hiding Br Tags In Textarea (flatfile-editinplace Cms)
I recently made a flatfile cms (+ edit in place). Here's an example of how it shows the <br>'s when hitting enter. The password is demo. Now when you click inside (in any text field - there are 4), when hitting enter it makes a new line without showing a <br> tag. Clicking outside and inside the textarea, it will show all the line breaks you've made.
My question is how to hide the <br> tag. What I've searched, found and tried the following: Code: [Select] $content=nl2br($content); and $content = str_replace("<br>", "\n", $content); Neither worked. Also when using this code Code: [Select] $file1 = include '/ccms/files/edit.txt'; echo $file1; // This outputs the file. to show the content on another page, it adds a number 1 to every textarea I have on the original page. You can preview the number 1 error here. Similar TutorialsI have the pre tags stored in the database like in the following example:
<pre> ... </pre>I am looking to avoid having the code rendered, when querying it into a textarea. Any suggestions? The pre tags: <pre></pre>get saved in the database like in the above shown example. Though, when reopening them within a textarea they stop working. For example: <pre><h1>The Headline</h1></pre>becomes: The Headline within the textarea. The Questions: What happens here? How to solve it? Edited by glassfish, 03 October 2014 - 09:42 AM. Well, I had this working perfectly until they stopped using a mysql database and started using a flatfile. What it should do: Grab data from the flatfile, trim the unwanted parts and set it in an array. With the received data display as an image. I am very confused about how I would do this. My current code: signature.php: Code: [Select] <?php //GET AND TRIM $fileName="accounts.txt"; $fileHandle = fopen($fileName,"r"); $filecontents = fread($fileHandle,filesize($fileName)); $exploded = explode(" ",$filecontents); $name=""; $balance=""; $accounts=array(); $num=0; for($i=0;$i<count($exploded);$i++) { $line = explode("\t",$exploded[$i]); for($a=0;$a<count($line);$a++) { if(trim($line[$a])=="player") { }elseif($line[$a]=="money") { }elseif($line[$a]=="type") { }elseif(trim($line[$a])=="{") { }else { $subline = explode("\r",$line[$a]); for($e=0;$e<count($subline);$e++) { if(trim($subline[$e])=="}") { } elseif(is_numeric(trim($subline[$e]))) { $balance=trim($subline[$e]); } else { $name=trim($subline[$e]); } if($name!=""&&$balance!="") { $temp=array($name=>$balance); $accounts[$num]=$temp; $num++; $name=""; $balance=""; } } } } } //Image Generation require_once('../func.inc.php'); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $font = "minecraft.ttf"; $user=""; if(isset($_GET['u'])) { if(!empty($_GET['u'])) { $user = $_GET['u']; } } if(isset($_GET['i'])) { if(!empty($_GET['i'])) { $img = $_GET['i']; } else{$img='1';} } else{$img='1';} if(isset($_POST['u'],$_POST['i'])) { if(!empty($_POST['u'])) { $user=$_POST['u']; } if(!empty($_POST['i'])) { $img = $_POST['i']; } } if(in_array($user, $accounts)) { //Info Grabs $money = get_balance($user); //End Info Grabs } else { die("That is an invalid player."); } //Display Image $user = ucfirst($user); $image = imagecreatefrompng("images/".$img.".png"); $color = imagecolorallocate($image, 255,255,255); if ($_GET['i'] >= '8') { ImageTTFText ($image, "8", 0, 100, 13, $color, $font,"Name:"); ImageTTFText ($image, "8", 0, 138, 13, $color, $font,$user); ImageTTFText ($image, "8", 0, 240, 13, $color,$font,"Money:"); ImageTTFText ($image, "8", 0, 285, 13, $color,$font,"$".$money); } else { ImageTTFText ($image, "7", 0, 246, 10, $color, $font,"Spartan Universe"); ImageTTFText ($image, "12", 0, 130, 50, $color, $font,"Name:"); ImageTTFText ($image, "12", 0, 130, 96, $color,$font,"Money:"); ImageTTFText ($image, "12", 0, 185, 50, $color, $font,$user); ImageTTFText ($image, "12", 0, 198, 96, $color,$font,"$".$money); } //End Image Display header("Content-type: image/png"); imagepng($image); imagedestroy($image); ?> accounts.txt: Code: [Select] arkangel011 { type player money 23.47 } chemicalbacon { type player money 203.89 } func.inc.php Code: [Select] <?php function get_players() { $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("minecraft",$con); $query = "SELECT * FROM `lb-players` ORDER BY `lb-players`.`playername` ASC "; $res = mysql_query($query,$con); while($row = mysql_fetch_assoc($res)) { echo "<option value='".$row['playername']."'>".$row['playername']."</option>"; } } function is_valid_player($user) { $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("minecraft",$con); $query = "SELECT COUNT(playername) AS count FROM `lb-players` WHERE `playername` = '".$user."'"; $res = mysql_query($query,$con); $row = mysql_fetch_assoc($res); if($row['count']==1) { return true; } else { return false; } } function get_balance($name) { $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("iconomy",$con); $query = "SELECT * FROM `iconomy` WHERE `iconomy`.`username` = '".$name."'"; $res = mysql_query($query,$con); $row=mysql_fetch_array($res); //echo $row['balance']; mysql_close($con); return $row['balance']; } function update_economy() { $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("iconomy",$con); $fileName="accounts.txt"; $fileHandle = fopen($fileName,"r"); $filecontents = fread($fileHandle,filesize($fileName)); $exploded = explode(" ",$filecontents); $name=""; $balance=""; $accounts=array(); $num=0; for($i=0;$i<count($exploded);$i++) { $line = explode("\t",$exploded[$i]); for($a=0;$a<count($line);$a++) { if(trim($line[$a])=="player") { //unset($line[$a]); }elseif($line[$a]=="money") { //unset($line[$a]); } elseif($line[$a]=="type") { //unset($line[$a]); } elseif(trim($line[$a])=="{") { //unset($line[$a]); } else { //echo $line[$a]."<br>"; $subline = explode("\r",$line[$a]); for($e=0;$e<count($subline);$e++) { //echo $subline[$e]."<br>"; if(trim($subline[$e])=="}") { //unset($subline[$e]); } elseif(is_numeric(trim($subline[$e]))) { //echo $subline[$e]."<br>"; $balance=trim($subline[$e]); } else { //echo $subline[$e]."<br>"; $name=trim($subline[$e]); } if($name!=""&&$balance!="") { $temp=array($name=>$balance); $accounts[$num]=$temp; $num++; $name=""; $balance=""; } } } } } foreach($accounts as $account=>$balance) { foreach($balance as $name=>$dollar) { $query = "UPDATE `iconomy`.`iconomy` SET `balance` = '".$dollar."' WHERE `iconomy`.`username` ='".$name."'"; mysql_query($query,$con); //echo "Name: ".$name; //echo ": Balance: ".number_format($dollar,2); //echo "<br>"; } } } ?> I have a form that generates html code, and displays it in a textarea with submit button. I want to submit button to take the data entered in that textarea1 on page 1, and upload to textarea2 on page 2 How can I do this? I have no idea where to start. hi everyone, did not know what to make the subject, but here is what I want to do: I have a string, which gets returned to me from a linux app on my server, it looks something like this: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> <TITLE> </TITLE> <META NAME="GENERATOR" CONTENT="OpenOffice.org 3.2 (Linux)"> <META NAME="AUTHOR" CONTENT="Administrator"> <META NAME="CREATED" CONTENT="20110106;14170000"> <META NAME="CHANGEDBY" CONTENT="HOD"> <META NAME="CHANGED" CONTENT="20110522;16540000"> <STYLE TYPE="text/css"> <!-- @page { margin: 0.26in } P { margin-bottom: 0.15in; direction: ltr; color: #000000; line-height: 0.15in; text-align: justify; widows: 2; orphans: 2 } P.western { font-family: "Arial", sans-serif; font-size: 10pt; so-language: en-US } P.cjk { font-family: "Batang", "바탕", serif; font-size: 10pt } P.ctl { font-family: "Times New Roman", serif; font-size: 10pt; so-language: ar-SA } A:link { color: #0000ff } --> </STYLE> </HEAD> <BODY LANG="en-US" TEXT="#000000" LINK="#0000ff" DIR="LTR" STYLE="border: 5.05pt double #000000; padding: 0.67in 0.92in"> <P>I want this and the tags around it, just not the html, head, body and their closing tags.</P> </BODY> </HTML> within the body, the tags are each styled for example: <p style="color: red"></p> so I cannot just get rid of all html, I want to get only all the content within the body tags, but without the body tags obviously strip_tags does not work as i need, I only want to strip certain tags. If someone can help me with this i will much appreciate it. I am asking out of curiosity, how does this problem usually get solved, when using a tag system to sort content, and users enter similar tags. For example: flower and flowers... which means the difference between singular and plural. Judging by other sites which are around, this problem is not solved at all, they simply let you add as many tags as you want and then rank the most used tags, it indeed is a solution, but seems more like a walk-around solution to me. Any ideas how somebody could approach to solve this one? EDIT: My suggestion would be an analysis function, which analyzes the entered tag and then suggests the user that similar tags have been already entered and perhaps he wants to choose one of those which have been already entered. This does work though with a high traffic websites what can happen is the following: php and php5 You can end up with two similar tags which are both widely used though have different meanings to the user base. This one could be solved by simply prohibiting similar tags with little additions or changes, and so to speak "forcing" the user to choose something which is already there. May be a way, though it can turn out as a bad solution as well. Do anyone know how i can put the html tags in the same line as the other html tags? Here's an example: Code: [Select] Images | Link | Delete | Enabled On my code, it break the tags to the new line without put on the same line as the other tags. Here's the code: Code: [Select] [code]<?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, public FROM members WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?id='.$row['id'].'">Delete</a> </td> | <p> <p id="test">'.$row['Public'].'</td>''; } } } ?>[/code] Say I have the following text stored in a MySQL database... Code: [Select] <b>Classic Quote from movie</b> and I retrieve it into a variable called $text, how do I properly echo that so that it keeps the bold tags and actually display the text "Classic quote from movie" in BOLD? I'm doing something wrong somewhere along the line (simply doing "echo $text;") because it displays on the page as... Code: [Select] <b>Classic Quote from movie</b> Instead of... Classic Quote from movie Any info on properly storing and echoing back HTML would be very appreciated. Hi people! I have this code: if ($_POST['remember'] == true) { // COOKIES ON! $time = time() + 20000; setcookie(user, $username, $time); setcookie(pass, $password, $time); header("Location: index.php"); echo "<h1 class='welcome'>Welcome ".$_COOKIE['user']." |</h1>"; echo "<div id='divlogin' style='visibility:hidden'></div>"; echo "<a href='logout.php'><h1 class='logout'><b>Logout</b></h1></a>"; }elseif ($_POST['remember'] == false){ echo "<div id='divlogin' style='visibility:hidden'></div>"; echo "Div hidden!"; } "remember" - is a checkbox. So, if the checkbox is checked then I will activate the cookies and hide the divlogin (till now everything is fine), but if the checkbox isn't checked, I will just hide the divlogin (and this don't happen), however, the echo "Div hidden!" works nicely. The code detects if the checkbox is checked or not, the only problem is that if isn't checked the div doens't hide. Any ideas? Thanks When I display my database entries, I want to hide some of the data. As you can see in this example: http://www.beat-the-spread.net/week1.php What I'd like to do is leave all the cells blank where the spread is zero. Here's the code I'm using: Code: [Select] while($row = mysql_fetch_array( $result )) { $i=1; if ($row['game_id']='$i') { echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['team_name']; echo "</td><td>"; echo $row['owner']; echo "</td><td>"; echo $row['pt_spread']; echo "</td><td>"; echo $row['team_pts']; echo "</td><td>"; echo $row['team_bet']; echo "</td><td>"; echo $row['team_cover']; echo "</td><td>"; echo $row['owner_pts']; echo "</td></tr>"; if ($table_row_count % 2 && $table_row_count != 0) { echo ' <tr style="height: 8px"></tr> '; } $table_row_count++; } $i++; } echo "</table>"; I've been fooling with this for a couple hours and can't seem to find a decent way to do this. Can anybody help with this? Thanks. Hi! I have got an array which contains messages for different types of errors on my website (for login errors and such). My problem is however, that when the array is empty it still shows the message box (the CSS). here is the code I am using: Code: [Select] public function showMessages() { if (count($this->_messages > 0)) { echo '<div id="messages">'; foreach ($this->_messages as $msg) { echo $msg . '<br />'; } echo '</div>'; } } I am starting to think that I need to be doing this in JavaScript. I would prefer to do it using PHP only, if it is possible though. Thanks for the help! Hello, What if I wanted to publish a php program but want to hide the code so that even buyers would not get a look at it despite having the program fully functioning on their servers, is there a means through which I can hide the code so that it won't be shown even when the .php files are opened in a text editor? Hi all I have a website which has a payment system on it, I use sagepay, paypal and a few others. They all have relatively similar forms, in which the total amount to be paid is passed in a hidden form field, such as <input type="hidden" name="amount" value="25"> all the payment gateways I use have the same or similar method to send the total amount (ie: 25) for example, my paypal form is like <form action="https://www.paypal.com/cgi-bin/webscr" name="paypal_form" method="post">"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="item_name" value="items"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="notify_url" value="complete.php"> <input type="hidden" name="return" value="complete.php"> <input type="hidden" name="cancel_return" value="complete.php"> <input type="submit" name="submit" value="PayPal" /> </form> this is all fine, apart from the user can use things like "firebug" to alter the total to be paid, so they can change $25 to $4 for example. So my question is, is there anyway with PHP to send over these form values are hidden variables. My idea was to post my form fields apart from the "cost" to a PHP script, then get PHP to grab the total from the database and dump the value in cost field and send it along with the other posted values. So really, is there anyway to get PHP to process a form data in a hidden enviroment, so my payment form URL is something like process.php and then process.php on my server deals with the sending of the paypal form data, but in a way that the user cannot see this data, so they basically never get to see the paypal form and any of its contents. Hopefully that kind of makes sense I have tried so many ideas, but cannot seem to find a solution, although when I do, hopefully the same method can be used on all my payment forms. Thanks tons in advance I'd like to play music in the background of a page, but don't want to display the url of the music files in the source code or encrypt it. Is that possible to do using php? Hi there, Is it possible to hide text on a page using PHP? For example, hide the word "hello" every time it appears on the page? Or have it display in a different color? Ok so I have a website with two types of photo gallerys. Model Cars and Model Planes. The galleries are becoming so big that I need to add an archive link to the galleries, but it's messy to have the archive link there until we actually enable the archived photos. So what I want to do is show the DIV with the archive link in it if the page can find database a 1 in the model_pictures.car_gallery AND model_pictures.archive. How would I achieve this? The page is already connected to the database as it's pulling the images and information for the gallery. I need it to scan the entire 'archive' column in the database and also the 'car_gallery' and if it finds 1's in there AND the car_gallery then to show the link. What I would like to avoid, as I have two galleries, is having the archive link show on the car gallery when it finds a 1 in the archives column, but that archive is for a plane_gallery photo. Hence why I would like to have check both car_gallery + archive and then plane_gallery + archive. Any help would be greatly appreciated. Hi I am trying to hide the image filepath and found this tutorial http://www.bounmis.com/en/PHP/How_To_Hide_Image_Source.html which I am currently using. It works but I need an additional security here so this script parses images only if the user is logged in to wordpress here's what i have so far: <?php include('wp-config.php'); $wp->init(); $wp->parse_request(); $wp->query_posts(); $wp->register_globals(); Header('Content-type: image/jpeg'); $exp=GMDate('D, d M Y H:i:s',time()+999); Header('Expires: $exp GMT'); $image_path = 'pathtoimages/'; $file=$image_path . $_GET["img"]; // getting image name and your image path if ( is_user_logged_in() ) { $file=$image_path.'authorized.jpg'; } else { $file=$image_path.'notauthorized.jpg'; }; if (file_exists($file)){ $info=getimagesize($file); $width=$info[0]; $height=$info[1]; if ($info[2]==1){ $img=@imagecreatefromgif($file); } else if ($info[2]==2){ $img=@imagecreatefromjpeg($file); } else if ($info[2]==3){ $img=@imagecreatefrompng($file); } else { $width=800; $height=600; $file = 'notauthorized.jpg'; // if there is not such image, it will show default image $img=@imagecreatefrompng($file); } ImageJpeg($img); imagedestroy($img); } ?> the script doesnt work. I think it's because i set headers Header('Content-type: image/jpeg'); What can I do to make it work? Please help thanks Hi I want to hide the login box's of my webpage once you login. I have thought of two ways of doing it but which one would you say is better practice? 1. use a PHP if statement to echo 'Display: none on css' - when viewing source code it still shows the form but not displayed on page itself 2. use a PHP if statement around the whole <form></form> so it physically doesnt write the html if already logged in? Or if anyone has a better way it would be appreciated if you would share it? Thanks in advance I am building a member-based website, and I've got a bunch of buttons that lead from page to page. The links for these buttons are generated based on user ID and subsequent pages receive this variable as well. So, if you hover over the buttons, you get a link like this: http://www.mysite.com?id=423 How can I hide the last part? The '?id=423'? I must use this format of variable, and cannot resort to session variables. Is there a way to hide this portion of the links?? Hi all, I am going to be offering downloads on my site to members. However i want to somehow hide the download link so that they are unable to copy and paste and give it to their friends. IE, they have to be logged into my site to be able to download it else its not possible. Any ideas? Thanks Jake! PS. Not sure if this is the correct forum. |