PHP - Removing Only The First Line Break At The Beginning Of String
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 Similar TutorialsHow 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" ?> I have a regex that validates a string.
I want to ensure there is no space in the string.
Thus far I have used the negative look ahead regex construct as shown below to match strings without spaces.
(?!.*(\s))While this prevents space in between a word, all strings with space characters at the end or beginning are getting validated. I do not want that at all. This is the full regex script below: $string = "#JebiamgoOeing0"; if (preg_match('/^.*(?=.{8,})(?!.*([A-Za-z0-9])\1{1})(?=.*[a-z])(?=.*[A-Z])(?!.*(\s))(?=.*[\d])(?=.*[\W]).*$/', $string)) { "do something"; } else { "do something else"; }I need help in resolving this. Thank you. Edited by terungwa, 25 October 2014 - 12:50 PM. I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this! 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? 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. I want to have a line break between the lastname and the age. Please help. echo $line["firstname"].' '.$line["lastname"].' Age is'.$line["age"].'!'; 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? 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? 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. 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) 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 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> What I want to do is simple: The string "this_is_an_example.php" should return "this_is_an_" while: "this_is_an_example_filename.php should return "this_is_an_example_" Is there a simple function which can cut off the part after the last _ ? I have been looking and trying several functions, but can't seem to find the right one for this. (the last _ being cut off of course wouldn't be a problem I couldn't live with :-) ) Any help will be greatly appreciated! The table in the script has a set max-width. How can now a too long continuous text string as in "blaaaaaaaa", which also does not contain a space or dash, be broken, so the table does not become stretched to far? Which function is used for this? hi im having trouble removing ' from strings
so say
$name = "D'vion";
$newname = str_replace("'","",$name);
but this just returns the same.
thanks matt
Hello Everyone, I am working on a project I pull the field names from the database. I am trying to remove the underscore (_) when the field name is displayed. Does anyone know how I would do that? Here is the code that I am working with Code: [Select] $i = 0; while ($i < mysql_num_fields($fieldnamesquery_result)) { $meta = mysql_fetch_field($fieldnamesquery_result, $i); if (!$meta) { echo "No information available"; } $meta = str_replace("_", " ", $meta); $tablecolumn .= "<p>" . $meta->name . ":<input type='text' name='" . $meta->name . "' id='" . $meta->name . "' /></p>"; $i++; Hello guys, I want to remove part of a string and convert it to a var instead of echoing it out.. How would I do it.. $string = "temp_photo/testing.jpg"; I want to remove temp_photo so the out put should be $filename2 = testing.jpg Please advise.. Thanks, Dan Hey all, I'm using the form 'method="get" action="results.php"' on my search form... Say someone uses my 'Photo search' to search my database for aircraft, and leaves all fields blank. In this case, the only field of the search is 'aircraft'. This will take the user to 'results.php?aircraft='. Is there anyway to remove the sting if there is no search value? So it would just read 'results.php'? This is the code i have so far: Code: [Select] <?php if(isset($_GET['aircraft'])){ $aircraft = $_GET['aircraft']; } if($aircraft==""){ $aircraft = mysql_query("IGNORE aircraft"); } ?> Thanks in advanced! |