whitespace

This is a discussion on "whitespace" within the PHP Forum section. This forum, and the thread "whitespace are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 22nd, 2007, 08:46
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
whitespace

what was that function to take whitespace out of a string? cheers
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 22nd, 2007, 10:02
Junior Member
Join Date: Apr 2006
Location: UK
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: whitespace

You can use trim to get rid of whitespace at the begining and end of a string
PHP: Select all

$nospaces trim($string); 

Or use str_replace to remove whitespace throughout a string

PHP: Select all

$nospaces str_replace(' '''$string); 


HTH
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 22nd, 2007, 10:54
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: whitespace

Or preg_replace:
PHP: Select all

$result=preg_replace('/[^ ]/','','input text'); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 22nd, 2007, 12:18
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: whitespace

just what I needed thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Sep 23rd, 2007, 17:33
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: whitespace

how would i do the following:
$string = str_replace('<script HERE >', '<b>BLOCKED CODE</B>', $string);

how can i change HERE to a wildcard,

so the following would be replaced:
<script>
<script src="mal.js">
<script type="text/javascript">

thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Sep 23rd, 2007, 18:04
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: whitespace

Haven't tested this but it should work:
PHP: Select all

$string preg_replace('/<script [.]*>/''<b>BLOCKED CODE</B>'$string); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Sep 23rd, 2007, 18:19
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: whitespace

it didn't work
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Sep 23rd, 2007, 19:25
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: whitespace

use .*? rather that [.]* ... and take out the leading space ahead of the [.] too if you want it to work on <script> alone.

The match you have in the example in previous posts is a greedy one that will match up to the last >; you want a sparse match to only go as far as the next >.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Sep 23rd, 2007, 19:43
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: whitespace

okay this is my function for anyone who wanted to know

PHP: Select all

 $string preg_replace('/<script .*?>/''<strong>BLOCKED CODE</strong>'$string); 
    
$string preg_replace('/<script>/''<strong>BLOCKED CODE</strong>'$string); 
    
$string preg_replace('/<script/''<strong>BLOCKED CODE</strong>'$string); 
now the next problem is the php remover:

PHP: Select all

             $string = addslashes($string);
            $string = str_replace('<?', '<b>BLOCKED CODE</B>', $string);
            $string = str_replace('
?>', '<b>BLOCKED CODE</B>', $string);
it works fine but if the string to be filtered was:

PHP: Select all

 $string = "<?php echo $dbpass ?>";
it would still echo the password, if this was called after the filter:

PHP: Select all

 echo $string
so how can i change any variable ($test1, $_test etc)
to
HTML: Select all
"<b>BLOCKED CODE</B>"
sorry if that isn't clear :/
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Sep 23rd, 2007, 20:01
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: whitespace

Here's a regex to check if a string is a valid PHP variable. See if you can modify this to work:
PHP: Select all

 preg_match('/^\$[A-Z_][A-Z0-9_]*$/i',$t
lol, I think you should teach yourself a bit about regular expressions. The basics are easy to learn and you can do some really cool stuff with them.

Start here: http://www.regularexpressions.info
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Sep 23rd, 2007, 20:02
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: whitespace

thanks i googled about and i didn't find much
+ rep for both
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Sep 23rd, 2007, 20:02
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: whitespace

edited my post above.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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
removing whitespace dudester123 Web Page Design 3 Sep 1st, 2006 14:23
Making an image a link adds whitespace I can't get rid of sgware Web Page Design 5 Aug 18th, 2006 22:38
Meta tags causing random whitespace in IE? Tino Web Page Design 4 Aug 7th, 2006 20:32
store whitespace but not interpret it in <br> ktsirig PHP Forum 2 Apr 13th, 2006 18:46
Preserve Whitespace in DOM Object Problem ivan Other Programming Languages 0 Jan 27th, 2006 08:28


All times are GMT. The time now is 06:00.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42