Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Miller, Terion



On 7/29/09 1:34 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

On Wed, 2009-07-29 at 11:29 -0700, Miller, Terion wrote:
 I am trying to get rid of empty whitespace lines, I can't us chop() because
 as I read it it will remove all whitespacesright?

 Right now my db is outputting with extra lines, I have stripped tags I know
 it isn't that causing it to look like this

 Blahlajdlkfjlksdjflkdjsf

--how do I get rid of all this extra space?

 alkdfjlsdakjflsakdjflksjdf


Some example of where this is occurring in your code might help. HTML
output will ignore whitespace such as this unless it is asked explicitly
to preserve it, with a pre tag or CSS.

Thanks
Ash
www.ashleysheridan.co.uk



Well the html displays fine, its when I view the CSV in the db, I see the extra 
space, and I'm writing an application to reverse publish some of our site 
materials to the paper (I work for a newspaper) and the Quark output is picking 
up that extra space that is in the db (does that make sense?)

Here is what the CSV looks like (See all that linespacing?)  :

;2009-01-20;Inspection;Will re-test dishwashing machine and sanitizer 
buckets for proper concentration, in addition to reviewing critical items, 
during time of re-inspection.;5;




 Employee drink found uncovered, sitting next to clean bin of eating 
utensils. This is a repeat violation.












 Sanitizer bucket holding wiping cloths was found at 0 ppm chlorine; must 
maintain concentration of solution at 50-100ppm chlorine to effectively 
sanitize food contact surfaces.






 Can opener blade found encrusted with dust and dried-on, black, food 
debris; must maintain clean food contact surfaces under frequent cleaning 
regiment, so as to not risk cross-contamination to food.






 Dishwashing machine found not effectively sanitizing as it measured 0 ppm 
chlorine; must maintain dishwasher so that it consistently and adequately 
sanitizes food contact surfaces. Corrected on site. This is a repeat violation.


My code for the original insertion to the db is this(shortened up though)

or ($i=0; $i  count($results[0]); $i++) {$name1 = 
strtolower($results[1][$i]);$name = ltrim($name1);$address = 
strtolower($results[2][$i]);$inDate = strtotime($results[3][$i]);   
 $inType = strip_tags($results[4][$i]);$notes = 
strip_tags($results[5][$i]); $critical = strip_tags($results[6][$i]);   
 $cviolations = strip_tags($results[7][$i]);$noncritical = 
$results[8][$i];//trying to manipulate different field data
$cleanViolations = str_replace('*', '', $cviolations);$ucName = 
ucwords($name);$ucAddress = ucwords($address);$formatDate = date('ymd', 
$inDate);  //escaping strings good coder$mysql_name = 
mysql_escape_string($ucName);$mysql_address = 
mysql_escape_string($ucAddress);$mysql_inDate = 
mysql_escape_string($formatDate);$mysql_inType = 
mysql_escape_string($inType);$mysql_notes = mysql_escape_string($notes);
$mysql_critical = mysql_escape_string($critical);$mysql_cviolations = 
mysql_escape_string($cleanViolations);$mysql_noncritical = 
mysql_escape_string($noncritical);   //insert each to the database   
//attempt loop for checking restaurants // First check if the name exists $sql 
=SELECT * FROM `restaurants` WHERE `name`='{$mysql_name}' AND `address` 
='{$mysql_address}'; $result = mysql_query($sql) or die(mysql_error()); if 
(mysql_num_rows($result)  0){ $row = mysql_fetch_array($result);   $ID = 
$row['ID'];   // This means the name exists.. UPDATE inspections table
$sql = INSERT INTO `inspections` (ID, inDate, inType, notes, critical, 
cviolations, noncritical)  VALUES (;$sql .= '$ID', '$mysql_inDate', 
'$mysql_inType', '$mysql_notes', '$mysql_critical', '$mysql_cviolations', 
'$mysql_noncritical');mysql_query($sql); } else{// The 
name doesn't exists, add all the info  $sql = INSERT INTO `restaurants` 
(name, address)  VALUES (;  $sql .=  '$mysql_name', '$mysql_address');   
 mysql_query($sql); $ID = mysql_insert_id(); $sql = INSERT 
INTO `inspections` (ID, inDate, inType, notes, critical, cviolations, 
noncritical)  VALUES (;$sql .=  '$ID', '$mysql_inDate', '$mysql_inType', 
'$mysql_notes', '$mysql_critical', '$mysql_cviolations', 
'$mysql_noncritical');mysql_query($sql); } /**/ };





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Ashley Sheridan
[snip/]

Have you thought of just using a regular str_replace() on your code? You
can ask it to replace newlines and carriage returns with nothing and see
if that fixes you problem?

Thanks
Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Getting rid of extra lines

2009-07-29 Thread Bob McConnell
From: Miller, Terion

/* snip */

Before anyone can tell you how to fix it, you need to find out what is
causing that white space. is it empty lines, vertical tabs, thousands of
spaces, ...? Once you find that out, it is pretty easy to decide how to
get rid of them. Can you save the output to a file and open it with a
hex viewer?

Bob McConnell

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Jim Lucas
Miller, Terion wrote:
 I am trying to get rid of empty whitespace lines, I can't us chop() because
 as I read it it will remove all whitespacesright?
 
 Right now my db is outputting with extra lines, I have stripped tags I know
 it isn't that causing it to look like this
 
 Blahlajdlkfjlksdjflkdjsf
 
--how do I get rid of all this extra space?
 
 alkdfjlsdakjflsakdjflksjdf
 
 

If the white space is included in data coming from the db you could run
a simple little regex on the variable to removed any repetitive white
space.  But it might not be the best way to do it.

$clean = preg_replace('|\s+|', ' ', $input);
or
$clean = preg_replace('|\s{2,}|', ' ', $input);

If the white space is being generated in your HTML output, but is not in
your data store, then you need to cleanup your PHP code and that might help.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Miller, Terion



On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

[snip/]

Have you thought of just using a regular str_replace() on your code? You
can ask it to replace newlines and carriage returns with nothing and see
if that fixes you problem?

Thanks
Ash
www.ashleysheridan.co.uk



Yep I have tried str_replace to get rid of \n and it didn't work
Boss mentioned to explode the var that is full of so many blank lines then put 
it back together..seems like there has to be an easier way...

This is what I tried:

 $tags = array('\n', 'br');$sNotes = str_replace($tags,, $notes);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Miller, Terion



On 7/29/09 2:19 PM, Jim Lucas li...@cmsws.com wrote:

$clean = preg_replace('|\s+|', ' ', $input);

Hi Jim,
The extra whitespace lines are in the data store, coming from it I'm going to 
try your method but is there a way to not have mySQL store it with so many 
lines (this is data being screen scraped and put in the db)
My code was at the beginning of this post of how I was inserting it.

Thanks
And Chocolate huh
Terion

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Jim Lucas
Miller, Terion wrote:
 
 
 On 7/29/09 2:19 PM, Jim Lucas li...@cmsws.com wrote:
 
 $clean = preg_replace('|\s+|', ' ', $input);
 
 Hi Jim,
 The extra whitespace lines are in the data store, coming from it I'm going to 
 try your method but is there a way to not have mySQL store it with so many 
 lines (this is data being screen scraped and put in the db)
 My code was at the beginning of this post of how I was inserting it.
 
 Thanks
 And Chocolate huh
 Terion
 

If the method that I give you works on the out from the db to the
browser, the should be no reason you cannot adapt whatever script you
are using for scrapping to use this function when it inserts the data
into the db.

Jim


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Jonathan Tapicer
On Wed, Jul 29, 2009 at 4:20 PM, Miller,
Teriontmil...@springfi.gannett.com wrote:



 On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 [snip/]

 Have you thought of just using a regular str_replace() on your code? You
 can ask it to replace newlines and carriage returns with nothing and see
 if that fixes you problem?

 Thanks
 Ash
 www.ashleysheridan.co.uk



 Yep I have tried str_replace to get rid of \n and it didn't work
 Boss mentioned to explode the var that is full of so many blank lines then 
 put it back together..seems like there has to be an easier way...

 This is what I tried:

     $tags = array('\n', 'br');    $sNotes = str_replace($tags,, $notes);

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



That didn't work because \n needs to be between   instead of ' '.

Jonathan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines (RESOLVED)

2009-07-29 Thread Miller, Terion



On 7/29/09 3:05 PM, Jonathan Tapicer tapi...@gmail.com wrote:

On Wed, Jul 29, 2009 at 4:20 PM, Miller,
Teriontmil...@springfi.gannett.com wrote:



 On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 [snip/]

 Have you thought of just using a regular str_replace() on your code? You
 can ask it to replace newlines and carriage returns with nothing and see
 if that fixes you problem?

 Thanks
 Ash
 www.ashleysheridan.co.uk



 Yep I have tried str_replace to get rid of \n and it didn't work
 Boss mentioned to explode the var that is full of so many blank lines then 
 put it back together..seems like there has to be an easier way...

 This is what I tried:

 $tags = array('\n', 'br');$sNotes = str_replace($tags,, $notes);

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



That didn't work because \n needs to be between   instead of ' '.

Jonathan


Thanks Guys, ended up using Jim's way before inserting it into the db and it 
works like a charm


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines (RESOLVED)

2009-07-29 Thread Jim Lucas
Miller, Terion wrote:
 
 
 On 7/29/09 3:05 PM, Jonathan Tapicer tapi...@gmail.com wrote:
 
 On Wed, Jul 29, 2009 at 4:20 PM, Miller,
 Teriontmil...@springfi.gannett.com wrote:


 On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 [snip/]

 Have you thought of just using a regular str_replace() on your code? You
 can ask it to replace newlines and carriage returns with nothing and see
 if that fixes you problem?

 Thanks
 Ash
 www.ashleysheridan.co.uk



 Yep I have tried str_replace to get rid of \n and it didn't work
 Boss mentioned to explode the var that is full of so many blank lines then 
 put it back together..seems like there has to be an easier way...

 This is what I tried:

 $tags = array('\n', 'br');$sNotes = str_replace($tags,, $notes);

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 
 That didn't work because \n needs to be between   instead of ' '.
 
 Jonathan
 
 
 Thanks Guys, ended up using Jim's way before inserting it into the db and it 
 works like a charm
 
 

Just to be clear.  Can you paste which one worked for you.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting rid of extra lines (RESOLVED)

2009-07-29 Thread Miller, Terion



On 7/29/09 3:16 PM, Jim Lucas li...@cmsws.com wrote:

Miller, Terion wrote:


 On 7/29/09 3:05 PM, Jonathan Tapicer tapi...@gmail.com wrote:

 On Wed, Jul 29, 2009 at 4:20 PM, Miller,
 Teriontmil...@springfi.gannett.com wrote:


 On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 [snip/]

 Have you thought of just using a regular str_replace() on your code? You
 can ask it to replace newlines and carriage returns with nothing and see
 if that fixes you problem?

 Thanks
 Ash
 www.ashleysheridan.co.uk



 Yep I have tried str_replace to get rid of \n and it didn't work
 Boss mentioned to explode the var that is full of so many blank lines then 
 put it back together..seems like there has to be an easier way...

 This is what I tried:

 $tags = array('\n', 'br');$sNotes = str_replace($tags,, $notes);

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 That didn't work because \n needs to be between   instead of ' '.

 Jonathan


 Thanks Guys, ended up using Jim's way before inserting it into the db and it 
 works like a charm



Just to be clear.  Can you paste which one worked for you.

This is what workedon my page that inserts the data to the db I put

 //stripping white line spaces$cleanNotes = preg_replace('|\s+|', ' ', 
$notes);$cleanVios = preg_replace('|\s+|', ' ', $cleanViolations);

then I mysql_escaped them and put them in the db, checked the csv and presto 
perfect no extra linespacing


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php