PHP - Break Lines
Good morning,
I passed a bunch of HTML tags over a function that delete then, keeping just the text between. The problem is, after that all the tags were replaced by line breaks. Something like this before the function: <tr> <td> Text </tr> </td> After the function the 4 tags were correctly removed but instead i receive just the string "Text" I receive 2 line breaks, the "Text" and other 2 line breaks, like this: Text In HTML code this line breaks has no tags like <br> or <p> it's just blanck lines. I need to get just the text, how can I get rid of then? I tried this and also didn't work. $text = str_replace("/n", "", $text ); Thanks Danilo Jr. Similar TutorialsI want to have a line break between the lastname and the age. Please help. echo $line["firstname"].' '.$line["lastname"].' Age is'.$line["age"].'!'; Code: [Select] $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].","; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } print $csv_output; I'm using the above to get a csv output in my browser, but it appears as a string of text eg a1,a2,a3,a4,b1,b2,b3,b4,... I'd like it to appear as a1,a2,a3,a4 b1,b2,b3,b4 c1,c2,c3,c4 Any ideas how? Hi all, I realised as users register themselves in the registration form, they wrote their comments and experience in the comment box which was provided Example (this is the content which they have written) 'Sentence 1 - Abccafsafsafafasdfafasfafs Sentence 2 - dasddsadsadsadsdaddsda' As you can see, between Sentence 1 and 2 there is a break (space). However when we store it in our database, and generate it out as a webpage, the break (space) is gone, and sentence 1 and 2 merged Example 'Abccafsafsafafasdfafasfafsdasddsadsadsadsdaddsda' My question is, how can we prevent 2 different sentences from merging? Thanks Below is my code and attached it what has been generated after we have posted it in webpage Code: [Select] cho '<div id="panel3">'; echo '<table>'; /***Tutor's Comments***/ echo'<div id="tutor_comments">'; echo '<br/><tr><td class="row_header">Tutor\'s Comments</td></tr>'; if (!empty($row2['tutor_comments'])) { echo '<tr><td>' . $row2['tutor_comments'] . '<br/><br/></td></tr>'; } /***Tutor's Commitments***/ echo '<tr><td class="row_header">Tutor\'s Commitment</td></tr>'; if (!empty($row2['tutor_commitment'])) { echo '<tr><td>' . $row2['tutor_commitment'] . '<br/><br/></td></tr>'; } /***Admin_comments***/ echo '<tr><td class="row_header">Admin\'s Comments</td></tr>'; if (!empty($row2['admin_comments'])) { echo '<tr><td>' . $row2['admin_comments'] . '<br/><br/></td></tr>'; } echo '</table>'; //End of Panel 3's table echo '</div>'; //End of tutor_comments DIV I'm trying to figure out how I can break a string down if the strings length is longer then lets say 140 characters including white space. At first I was figuring maybe maybe I could do something with explode or implode after I get a get my strings length but the string in question has no static values to them that would let me break it apart or put it back together. Now In most cases I would use substr() to return my 140 characters, however I need to take 140+ and make an array of the extra so I can run a for each on it. I am using this for an SMS app I am helping develop. I know I can limit my the output to only 140, just based on the notion that a single SMS is capped at 140-160 on most carriers. Unfortunately for me thats not the case so I need to break this apart and I am stumped, anyone got any ideas? why is it that when i saved it adds a break tag i dont understhand heres the code i cant find it its only when i save or remove a video and save it it has a break Code: [Select] <?php require "scripts/connect.php"; if($_POST['submitbtn']){ $video1 = mysql_real_escape_string(html_entity_decode($_POST['video1'])); $video2 = mysql_real_escape_string(html_entity_decode($_POST['video2'])); $video3 = mysql_real_escape_string(html_entity_decode($_POST['video3'])); $video4 = mysql_real_escape_string(html_entity_decode($_POST['video4'])); if($video1){ if($video2){ if($video3){ if($video4){ $query = mysql_query("UPDATE videos SET video1='$video1',video2='$video2',video3='$video3',video4='$video4'"); header("location: http://www.mywebsite.com/admin/editvideos"); }else $msg = "PLEASE FILL IN"; }else $msg = "PLEASE FILL IN"; }else $msg = "PLEASE FILL IN"; }else $msg = "PLEASE FILL IN"; } mysql_close(); ?> <?php include "header.php";?> <?php if($email){?> <?php include "inc/nav.php"; ?> <div id="righthomecontent"> <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM videos"); $rows = mysql_fetch_assoc($query); $video1 = stripslashes($rows['video1']); $video2 = stripslashes($rows['video2']); $video3 = stripslashes($rows['video3']); $video4 = stripslashes($rows['video4']); mysql_close(); ?> <center>MUST USE THIS IN VIDEOS ?wmode=opaque"</center><br> <center>All videos are Width='220' and Height='240'</center><br> <form class="editvideoform" action="editvideos" method="post"> <table> <tr> <td></td> <td><?php echo $msg;?></td> </tr> <tr> <td>VIDEO 1</td> <td><textarea cols=25 rows=10 name="video1"><?php echo $video1;?></textarea></td> </tr> <tr> <td>VIDEO 2</td> <td><textarea cols=25 rows=10 name="video2"><?php echo $video2;?></textarea></td> </tr> <tr> <td>VIDEO 3</td> <td><textarea cols=25 rows=10 name="video3"><?php echo $video3;?></textarea></td> </tr> <tr> <td>VIDEO 4</td> <td><textarea cols=25 rows=10 name="video4"><?php echo $video4;?></textarea></td> </tr> <tr> <td></td> <td><input type="submit" name="submitbtn" value="SUBMIT" /></td> </tr> </table> </form> </div> <?php } else { echo "<center><h1>PLEASE LOGIN</h1></center>"; } ?> <?php include "footer.php";?> echo '<div class="gamename">'.$values[0].'</div>'; echo '<div class="gameimage"><a href="'.$values[3].'"><img src="'.$values[1].'"></a></div>'; NOW i want 2nd echo under 1st echo. I tried every single <br> combination but no luck Also my 2nd question is: my image and link is a variable, it displays the image but there is something wrong with link. Variable is just like this www.mydomain.com\image\blabla.php but it shows link as==> www.mydomain.com\ instead of what i wrote above. How can i break down strings for example i have a simple search database for products where as a user searches a term this can be one, two three words and so on. I'm using a wildcard; but i want the best way to get the possible search so i would like to break down the string into separate words and then use that to search the database using wildcards is this possible? Thanks for reading. I have a chain of methods, is there anyway to end the chain half way through if some particular event happens? Here is an example (not the best but still an example): Code: [Select] <?php $age = $class->post("age")->callback(funciton(){ global $class; if($class->string() < 18){ // end the execution of the chain, doesn't execute toInt() } })->toInt(); ?> I was wondering if you guys could help me 'break' a function I've been working on. It converts a CSV-formatted string to a 2d array following RFC4180. Here's the function. /** * * Covert a multi-line CSV string into a 2d array. Follows RFC 4180, allows * "cells with ""escaped delimiters""" and multi-line enclosed cells * It assumes the CSV file is properly formatted, and doesn't check for errors * in CSV format. * @param string $str The CSV string * @param string $d The delimiter between values * @param string $e The enclosing character * @param bool $crlf Set to true if your CSV file should return carriage return * and line feed (CRLF should be returned according to RFC 4180 * @return array */ function csv_explode( $str, $d=',', $e='"', $crlf=TRUE ) { // Convert CRLF to LF, easier to work with in regex if( $crlf ) $str = str_replace("\r\n","\n",$str); // Get rid of trailing linebreaks that RFC4180 allows $str = trim($str); // Do the dirty work if ( preg_match_all( '/(?: '.$e.'((?:[^'.$e.']|'.$e.$e.')*+)'.$e.'(?:'.$d.'|\n|$) # match enclose, then match either non-enclose or double-enclose # zero to infinity times (possesive), then match another enclose, # followed by a comma, linebreak, or string end | ####### OR ####### ([^'.$d.'\n]*+)(?:['.$d.'\n]|$) # match anything thats not a comma or linebreak zero to infinity # times (possesive), then match either a comma or a linebreak or # string end )/x', $str, $ms, PREG_SET_ORDER ) === FALSE ) return FALSE; // Initialize vars, $r will hold our return data, $i will track which line we're on $r = array(); $i = 0; // Loop through results foreach( $ms as $m ) { // If the first group of matches is empty, the cell has no quotes if( empty($m[1]) ) // Put the CRLF back in if needed $r[$i][] = ($crlf == TRUE) ? str_replace("\n","\r\n",$m[2]) : $m[2]; else { // The cell was quoted, so we want to convert any "" back to " and // any LF back to CRLF, if needed $r[$i][] = ($crlf == TRUE) ? str_replace( array("\n",$e.$e), array("\r\n",$e), $m[1]) : str_replace($e.$e, $e, $m[1]); } // If the raw match doesn't have a delimiter, it must be the last in the // row, so we increment our line count. if( substr($m[0],-1) != $d ) $i++; } // An empty array will exist due to $ being a zero-length match, so remove it array_pop( $r ); return $r; } And to use it: $csv = 'this,will,"be ""separated""",by "commas,",,"should work with ""multiline,"", ",entries some,last,data,"test"'; print_r( csv_explode($csvn) ); or $csv_eurwin = "this;will;'be ''separated''';by\r\n"; $csv_eurwin .= "'semicolons;';;'should work with\r\n"; $csv_eurwin .= "''multiline;'';';entries\r\n"; $csv_eurwin .= "some;'last';data;'test'"; print_r( csv_explode($csv_eurwin, ';', '\'', TRUE) ); Thanks! Here's the actual spec if anyone cares Code: [Select] 1. Each record is located on a separate line, delimited by a line break (CRLF). For example: aaa,bbb,ccc CRLF zzz,yyy,xxx CRLF 2. The last record in the file may or may not have an ending line break. For example: aaa,bbb,ccc CRLF zzz,yyy,xxx 3. There maybe an optional header line appearing as the first line of the file with the same format as normal record lines. This header will contain names corresponding to the fields in the file and should contain the same number of fields as the records in the rest of the file (the presence or absence of the header line should be indicated via the optional "header" parameter of this MIME type). For example: field_name,field_name,field_name CRLF aaa,bbb,ccc CRLF zzz,yyy,xxx CRLF 4. Within the header and each record, there may be one or more fields, separated by commas. Each line should contain the same number of fields throughout the file. Spaces are considered part of a field and should not be ignored. The last field in the record must not be followed by a comma. For example: aaa,bbb,ccc 5. Each field may or may not be enclosed in double quotes (however some programs, such as Microsoft Excel, do not use double quotes at all). If fields are not enclosed with double quotes, then double quotes may not appear inside the fields. For example: "aaa","bbb","ccc" CRLF zzz,yyy,xxx 6. Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes. For example: "aaa","b CRLF bb","ccc" CRLF zzz,yyy,xxx 7. If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote. For example: "aaa","b""bb","ccc" hi i have some troubles to create a new line break for this code: i already tried: Code: [Select] echo "<input type='radio' name='gropu1' value='$id'>$data \n "; // Code: [Select] echo "<input type='radio' name='gropu1' value='$id'>$data.\n "; // Code: [Select] echo "<input type='radio' name='gropu1' value='$id' >$data.'\n'"; what is the correct syntax for that? hey guys i have to following code <?php include("users/index.php"); ?> <?php $LOGIN_INFORMATION = array( $user_login_username => $user_login_password, ); ?> the script connects to the database and fetches the data the problem im having is the table has 3 tables "ID" - "user_login_username" - "user_login_password" in those tables are 2 entries "1" - "test" - "user" "2" - "test1" - "user1" now on the login screen when i enter the username and password "test1" and "user1" it logs me in fine and works how i want it to but when i enter "test" and "user" it doesnt work if i add another entry so the table shows "1" - "test" - "user" "2" - "test1" - "user1" "3" - "test2" - "user2" and i try the to login again with "test" and "user" it fails and so does "test1" and "user1" but "test2" and "user2" works the script is only fetching the last entry from the DB is there anyway to login with any user in the DB?? if this dont make sense or you need more info please ask Thanks Can you please tell me what each of these lines of code means?
$allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); $length = 20; $newfilename = $_SESSION['user_id'].$_FILES["file"]["name"]; $thumbnail = $newfilename . "." . $extension; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $thumbnail); $sql = "INSERT INTO videos ( filename ) VALUES( $thumbnail )"; mysql_query($sql); $file_location = '<a href="http://www.--.com/upload/' . $thumbnail . '">' . $thumbnail . '</a>'; $description = $description . " \n " . $newfilename; Hello, I'm creating a program that analyzes information that is exported by another program. That program exports it in this way: Value1 Value2 Value3 Value4 Value1 Value2... In order to insert them in the database, I first have to know how many lines are inserted. They get send through HTML post. I already tried: $lines = explode("\n", $string); $number_lines = count($lines); But this always results in 1. How do I fix this? Regards, Chris My current code (which works): Code: [Select] <?php $body = explode("\n", $body); $body = array_slice($body, 3); $body = implode("\n", $body); ?> Is there a better way of doing this, so I dont have to explode and implode an array just to accomplish this? Working with authorize.net script that is included in my php. Trying to figure out how to use a variable beyond the 'case' I can do just about anything... inside the case... But I need to use the variable outside of there. Code: [Select] //several cases above case 5: $this->approval_code = $pstr_trimmed; break; // case 7 is the authorize.net transaction ID - This is the one I want to work with case 7: echo "Transaction ID: "; echo $pstr_trimmed; $trans_id_test = $pstr_trimmed; break; // but this below won't work. I can't use the variable anywhere outside of the case. echo "the new variable is now...".$trans_id_test; Hi, I'd like to know what the best way of breaking out of a nested foreach loop is..but not breaking out of the first foreach ears the code like, Code: [Select] foreach ($apts as $apt) { foreach($rdb as $rem) { // Check to see if we've already sent a reminder for this appointment if($apt->id == $rem->appid) { // TODO get out of this foreach and go to the next iterartion of the first foreach } } //rest of 1st foreach code here } is there some syntax i can put at the first foreach eg [here] and reference it within the second foreach continue[here]; or something? thanks, I think a switch break will help in this situation but I am definitely open to suggestions The problem I am have is that if there are 2 "Funner" or "Funnest" in the database then it displays duplicates in the in the column. I know that is what the code is telling it to do. If you look at the first row it should split them if there are 2 and display one in each column. In one time slot there is only allowed: - 1 Fun - 1 Funner or Funnest - 1 Funner or Funnest The case I am working with is there is 1 Fun and 2 Funners. The 2 Funners should split and display one in each "Funner/Funnest" column. There are planty of unique identifiers if someone has an idea for me. function taken($theType, $theTime){ $day_view = $_GET['date']; $DOP = explode("-", $_GET['date']); $topDOP = date("M", mktime(0, 0, 0, $DOP['1']))." ".$DOP['2'].", ".$DOP['0']; $dayDOP = date("l", mktime(0, 0, 0, $DOP[1], $DOP[2], $DOP[0])); connect(); $sql = "select * from party_times where dates = '$day_view' and paidID ='paid' and times = '$theTime'"; $result = mysql_query($sql) or die(mysql_error()); $day_count = mysql_num_rows($result); while($info = mysql_fetch_assoc($result)){ if($info['type'] == "$theType" && $info['times'] == "$theTime"){ $conID = "select DISTINCT confirmID from party_receipt where partyID = '".$info['partyID']."'"; $conqu = mysql_query($conID) or die(mysql_error()); while($con = mysql_fetch_assoc($conqu)){ $cid = $con['confirmID']; echo "<a href='party_booked.php?view=$cid'>RESERVED</a>"; }free($conqu); } }free($result); } Call the function: Code: [Select] <tr> <td width="25%"></td> <td width="25%" align="center">Fun</td> <td width="25%" align="center">Funner / Funnest</td> <td width="25%" align="center">Funner / Funnest</td> </tr> <tr> <td>11:00 AM</td> <td class = "res"><?php taken("Fun", "11:00 AM"); ?></td> <td class = "res"><?php taken("Funner", "11:00 AM"); ?></td> <td class = "res"><?php taken("Funnest", "11:00 AM"); ?></td> </tr> Thank you! I'm pretty new to php (as in I suck at it) so please bear with me. I have an entire site within a frame so that the domain name always shows up, without anything after it. Within the site I have a page using the "winxp progress bar" javascript that pops up a java notification and then redirects to another page when the user clicks the "OK" button - when this happens, I'd like to break the frame so that the full URL of the new page is displayed. In HTML this would be target="_top" but I'm not sure how to do it here. Here is the code for the entire page: Code: [Select] <html> <head> <title>Searching</title> <script language="javascript" src="xp_progress.js"> /*********************************************** * WinXP Progress Bar- By Brian Gosselin- http://www.scriptasylum.com/ * Script featured on Dynamic Drive- http://www.dynamicdrive.com * Please keep this notice intact ***********************************************/ </script> </head> <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red"> <table border="0" width="804" align="center"> <tr> <td width="794" align="center"> <h2 align="center"><font face="Verdana">Searching for <?php echo $_GET['id'];?> ...</font></h2> <p align="center"> <script type="text/javascript"> function redirectpage(){ bar3.togglePause() alert('<?php echo $_GET['id'];?> Found!'); window.location="lp.php" } var bar3= createBar(400,15,'white',1,'black','green',125,7,2,"redirectpage()"); </script> </p> </td> </tr> </table> </body> </html> "lp.php" is the final page and the one that should break the frame. I'm not sure whether this should be done inside the redirect on this page, or if it should be done inside lp.php. lp.php is just another redirect (there used to be some more things on it but I took them all out and had too many links pointing to it to bother changing them all). This is the entire contents of lp.php: Code: [Select] <?php header("Location: http://www.[urlremoved].com"); ?> I'm assuming it would be easier to put the frame break on this page, but I really have no idea. If someone can help me with it I'd really appreciate it. I'm trying to use SESSIONS, the start of my page looks like this: <?php session_start(); and the start of the source code looks like this: <br /> <b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by The <?php tag is on line 1, yet as you can see Notepad++ seems to add a <br /> before it, which results in the sessions not working. How can I fix this? so i have this string that i want to search on the database My database has 3 parts city, state, country and i have a string that is say "new york city, ny, united states" and i want to be able to be able to look into the database but search those three sections so for example "New York City" i would like to search under city "NY" i want it to search under state and "United States" i want to search under country so basically how can i split the string into those three sections?? hope someone can help me with this |