PHP - Inset Comma After Every Line Break
I am extracting data from one of the sites.I would join these sentences separated by , (comma). The solution that comes to my head is by inserting the text in the file and then using file functions.However, i was wondering if i can use str_replace here . Can anyone please point me in the right direction.
Code: [Select] Hospital 30-Day Death (Mortality) Rates from Heart Attack: 15.2% (No different than U.S. National Rate) Hospital 30-Day Readmission Rates from Heart Attack: % (Number of Cases Too Small*) Hospital 30-Day Death (Mortality) Rates from Heart Failu 10.5% (No different than U.S. National Rate) Hospital 30-Day Readmission Rates from Heart Failu 29.9% (Worse than U.S. National Rate) Hospital 30-Day Death (Mortality) Rates from Pneumonia: 9.8% (No different than U.S. National Rate) Hospital 30-Day Readmission Rates from Pneumonia: 20.6% (No different than U.S. National Rate) Similar Tutorialsecho '<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. I 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 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? 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? How do i get the first part of the string, all the way up until the string hits a line break? Code: [Select] <?php $string = "The quick red fox\n jumped over the brown\n lazy dog."; function first_of_string($str) { //php magic return $first_of_string; } echo first_of_string($string); //would produce "The quick red fox" ?> hi, i am using a database to populate a webpage with text. How do I make a function to add line breaks to the text? an example page I want to use it on it http://www.stayneartheairport.com/bandb.php?id=11084507&airport=manchester You can see the two text areas of description and facilities have no paragraphs or other formatting. I want the code to scan the text - and if there is say <br> - it will remove it an replace it with a line break. Hello, I have this XML file I am parsing and I have hit a small formatting issue that I can't seem to get around.
Here is what the the output of the RSS looks like.
<description><![CDATA[<div style='text-align:left;'>Exit ramp closed. <br/><b>Current Status:</b> Open<br/><b>Affected Lanes:</b> Exit Ramp<br/><b>Dates:</b> Wednesday, May 28 - Thursday, May 29<br/><b>Days Closed:</b> <font color='#808080'>S</font><font color='#808080'>M</font><font color='#808080'>T</font><font color='#FF0000'><b>W</b></font><font color='#FF0000'><b>T</b></font><font color='#808080'>F</font><font color='#808080'>S</font> 20:00 PM - 6:00 AM</div>]]></description>Notice at the first is "Exit ramp closed." There is nothing before it but, for some weird reason when I parse it. It is on a new line like so, notice it should be up there with "Incident" but, it is dropped down below it. Incident: Exit ramp closed. Current Status: Open Affected Lanes: Exit Ramp Dates: Wednesday, May 28 - Thursday, May 29 Days Closed: SMTWTFS 20:00 PM - 6:00 AMThis is how it is formated in the td cell. <td style='{$td2Style}'><strong>Incident:</strong> {$incident_data_desc}</td>\n";So as you can see above, there is nothing before it that would cause it to break to a new line both in the table or in the RSS. So how can I remove that first return only is that is on the same line with it and not below it. I have tried this and a couple of other things like trim with no luck. $description = $item->description; $incident_data_desc = str_replace("\r", '', $description );Note, I only need that first one removed, the others are fine. I can do it but it will remove all the breaks and I only want to remove that first one that is causing the line to be on a new line. Any suggestions? -Thanks how do I make this form here have a limit on the value's name, then it moves to the next line? Code: [Select] <form action=\"reply.php?com_id=$com_id\" method=\"post\"> <font color='brown'><u><input type=\"submit\" name ='submit' class=\"link\" value='$title'></u></font> </form> I am having problems with these slashes. They keep showing up when I echo data.... The code is to update a field in a mysql database table. Here is my code: Code: [Select] $query = mysql_query("SELECT * FROM `bus` WHERE username='$username'"); $row = mysql_fetch_array($query); $bio = $row['about']; $bio = str_replace("<br />","\r\n",$bio); if(isset($_POST['submit'])){ if(empty($errors)){ if($password == $pass){ $about1 = mysql_real_escape_string($_POST["about"]); $about1 = str_replace("\r\n","<br />",$about1); mysql_query("UPDATE bus SET about='$about1' WHERE username='$username'"); }else{$errors[] = 'Incorrect Password';} } } When I run this and put: About: I'm very tired today It's been very hard I get the about1 string as: I\\\'m very tired today\r\nIt\\\'s been very hard Why??? Hi, I am stuck on this point for few hours please can someone help. From one html form i am submitting two input boxes as array Code: [Select] <input type="text" name="names[]" /> <input type="text" name="position[]" /> <input type="text" name="names[]" /> <input type="text" name="position[]" /> <input type="text" name="names[]" /> <input type="text" name="position[]" /> Now when i submit i need to insert that values in a relational table ID name position I tried this way but dont know if i need to run two loops. $names = $_POST('names'); $positions = $_POST('position'); // now here i dont know how i will insert in database foreach ($names as $name) { foreach ($positions as $position) { $mysqlquery = ("INSERT into TABLE (name,position) values ($name,$position)"); } } Please any help how i will insert that Thanks Lets say I pull a value from a database field that has a value of 1,2 and what I want to do is seperate them and then run each of those values against a separate table how would that be accomplished. This seems like such a simple error, however I've no idea why I am getting it. apparently I have an unexpected comma on line 4 of the code below. I can't work out what the error is. Any ideas? Sorry to be a pain if it really is something simple, but I'm a bit new to all this php stuff. <?php function percentCalc($value1,$value2,$value3,$value4,$value5,$total) { $array=($value1,$value2,$value3,$value4,$value5); while (list($key,$arraycontent)= each($array)) { $c_percent=(($arraycontent/$total)*100); $final_array[]=$c_percent; } return $final_array; } ?> Hello Guys, I am trying to strip the last comma but I can't get it to work... Please advise Here is my code, it adds the coma in between all numbers and on the end. Code: [Select] $query1 = mysql_query("SELECT b_id FROM benefits"); while ($row = mysql_fetch_array($query1)) { $b_id = $row['b_id']; $b_id . ","; echo $b_id2; } displays 1,2,3,4,5,6,7,8,9,10, I also tried this but it didn't work. It removed all the commas Code: [Select] $query1 = mysql_query("SELECT b_id FROM benefits"); while ($row = mysql_fetch_array($query1)) { $b_id = $row['b_id']; $b_id . ","; $b_id2 = rtrim($b_id,','); echo $b_id2; } Hi, If I need to put commas within a variable how can this be achieved? i.e. if statement..... { $output = "text1,text2,text3"; Incase your wondering what I'm trying to do.. basically im using a header file on my site... i want different keywords within the meta tags depending on the page the user is on, so i want to include aprox 20 keywords in the $output which will be inserted in the comma area of the meta tags. Probably quite an easy way to do it but I'm not sure how to do it! Any help appreciated! Hey, i got this code which takes info from mysql: while ($row= mysql_fetch_array($result)) { $title = $row["alertid"]; $title2 = $row["alerttext"]; $title3 = $row["alertdate"]; $bla = "{\"alertid\":\"$title\",\"alerttext\":\"$title2\",\"alertdate\":\"$title3\"},"; echo "$bla"; } it is displayed like this: [{"alertid":"1","alerttext":"text1","alertdate":"date1"},{"alertid":"2","alerttext":"text2","alertdate":"date2"},{"alertid":"3","alerttext":"text3","alertdate":"date3"},] I wanted to ask, how can I remove the last comma, after date3"}, but keep other commas..? Hi All, I'm sure there is an easy solution for this but I am unable to find it. I am new to PHP and after a little help... the via data is stored in a database in this format... |51.105166,-1.695971|51.011055,-2.1068|50.945233,-2.617664|||| I'm trying to find a way of loosing the last comma if there are 1 or more entries, any ideas guys. What I'm getting is : Code: [Select] var points = [{location: '51.105166,-1.695971'},{location: '51.105166,-1.695971'},]; What I'm after is: Code: [Select] var points = [{location: '51.105166,-1.695971'},{location: '51.105166,-1.695971'}]; Code: [Select] <?php if($via != null){ echo "var points = ["; foreach($via as $point){ if($point != ""){ echo "{location:"; echo " '".$point."'"; echo "},"; } } echo "];\n"; } ?> Hi guys, Currently my result displayed a 'comma' at the end Lower Primary English, Math, Science, Chinese, How do I remove the comma which is bold in red? Thank you so much My code Code: [Select] while($row3 = mysqli_fetch_array($data3)) { if ($row3['level_id'] == 2) { echo ''.$row3['subject_name'].', '; } } After a lot of lurking, thanks for all the great topics I now have a guestion where I could really use your help. I am parsing some xml data with the following php: Code: [Select] <?php $data = file_get_contents("XML URL"); $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match); foreach ($match[1] as $actors) { echo $actors; } ?> For the following XML part: <actors> <actor id="1234">Actor #1</actor> <actor id="12345">Actor #2</actor> <actor id="123456">Actor #3</actor> </actors> This gives the ouput: Actor #1 Actor #2 Actor #3 Now I would like to separate the actor names by comma, like this: Actor #1, Actor #2, Actor #3 Does anybody know how to modify the php code for this? Thanks Code: [Select] 30|24|17,5|4|20,15|13|33,15|22|33,9|20|22 Let's say my output is that, Realistically every 3numbers is 1 Ticket they are seperated by a "," (comma) I want to wrap parenthesis around them so the output would look like this Code: [Select] (30|24|17) (5|4|20) (15|13|33) (15|22|33) (9|20|22) Now would I have to use regex.. or not cuz regex is extremely difficult Thanks |