Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 06-08-2005, 02:36 AM   #1 (permalink)
morpheuz
Code Monkey
 
Join Date: Feb 2005
Posts: 64
morpheuz is on a distinguished road
Can cascading text be converted to single line form?

Manual editing of html source to remove breaks (Enter) is annoying as hell. Is there a way to force text to single line in php?
morpheuz is offline   Reply With Quote
Old 06-08-2005, 03:46 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
ereg_replace() and preg_replace()
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 06-08-2005, 06:47 AM   #3 (permalink)
morpheuz
Code Monkey
 
Join Date: Feb 2005
Posts: 64
morpheuz is on a distinguished road
Documentation on the two is a little confusing to me and I can't even get php_strip_whitespace to work >_<. The word wrap function has given me the most success out of everything I tried so far. Those goddamn enter pushed line breaks seem to be above the law.

Can you give me a example from the functions you provided? I have html in a text file I'd like to do this to.
morpheuz is offline   Reply With Quote
Old 06-08-2005, 08:09 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
Just from teh top of my head
PHP Code:
$file "my_file.html";
$file_contents file_get_contents ($file);
$string_without_newline ereg_replace('\n'''$file_contents);
echo 
$string_without_newline
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 06-08-2005, 10:21 AM   #5 (permalink)
morpheuz
Code Monkey
 
Join Date: Feb 2005
Posts: 64
morpheuz is on a distinguished road
Very interesting, that code only seems to work within the browser. The source is still cascading when opened/remade, but the browser output is changed (though it still doesn't look like what I'm after). I can't see a use for this currently, but thanks anyways. I combined your code with fopen/fwrite/fclose. Here's what it looks like.

PHP Code:
<?
$file 
"tman.html"
$file_contents file_get_contents ($file); 
$string_without_newline ereg_replace('\n'''$file_contents); 
$np "tman.txt";
$o fopen($np,'w');
fwrite($o$string_without_newline);
fclose($o);
?>
morpheuz is offline   Reply With Quote
Old 06-08-2005, 11:17 AM   #6 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 676
DJMaze is on a distinguished road
Code:
ereg_replace('\n', '', $file_contents);
This should be double quoted
Code:
ereg_replace("\n", '', $file_contents);
Huge difference here
DJMaze is offline   Reply With Quote
Old 06-08-2005, 11:58 AM   #7 (permalink)
morpheuz
Code Monkey
 
Join Date: Feb 2005
Posts: 64
morpheuz is on a distinguished road
Definitely made the difference DJ, thanks. I still find it very interesting that this change doesn't translate when saving to text, it only effects html.

So, double quoting stuff makes sure you get the value of what's inside quotes? What is the purpose of using single quotes if this is the case?
morpheuz is offline   Reply With Quote
Old 06-08-2005, 01:31 PM   #8 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 676
DJMaze is on a distinguished road
'\n' = \n
"\n" = new-line

there's also \t, \r, \0, etc.
The difference between single and double is static vs dynamic strings

For example try:
Code:
$bob = 'hi it\'s me';
echo "$bob";

$bob = "hi it's me";
echo "\$bob";

$bob = "hi it's me";
echo '$bob';
That will hopefully explain it a bit.
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change line width in drawing applet/ allow text entry davidmccabe Java 0 03-16-2005 06:45 AM
Text Searching freesoft_2000 Java 2 12-02-2004 07:38 AM
javascript riddle: why won't my form submit from this text link? sde HTML, XML, Javascript, AJAX 6 09-29-2004 05:56 AM
cgi script Henry PHP 25 12-30-2002 06:54 AM


All times are GMT -8. The time now is 10:02 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting