php-general Digest 16 Sep 2006 10:25:02 -0000 Issue 4350
Topics (messages 241841 through 241858):
Re: Question on explode and join.
241841 by: Richard Lynch
readdir
241842 by: Toby Osbourn
241844 by: Brad Fuller
241850 by: Richard Lynch
241855 by: Larry Garfield
loadHTML/loadHTMLFile - DOM functions
241843 by: Leonidas Safran
241845 by: Rob
241846 by: Leonidas Safran
241848 by: Rob
241849 by: Rob
Re: Iteration through letter
241847 by: Martin Alterisio
Re: PHP and mySQL dates
241851 by: Richard Lynch
Re: Affiliate system
241852 by: Richard Lynch
Re: Filter MS Word Garbage
241853 by: Richard Lynch
Re: Open file on a Mounted Share on Mac OS X
241854 by: Richard Lynch
Re: security include from remote server
241856 by: Miguel Vaz
Please tell me I dont know regex
241857 by: william(at)elan.net
php and session issues continued...
241858 by: Dave Goodchild
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
php-general@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
$clean = $input;
foreach($badwords as $badword){
$clean = preg_replace('/(\\W)$badword(\\W)/ims', '\\1' .
str_repeat('*', strlen($badword)) . '\\2', $clean);
}
On Wed, September 13, 2006 11:51 am, Beauford wrote:
> Hi,
>
> I have a form which I want to check for inappropriate words before it
> is
> posted. I have used explode to put the string into an array using a
> space as
> the delimiter and then I check it against another array that contains
> the
> inappropriate words.
> I then replace the inappropriate words with *'s and join the array
> back into
> a string.
>
> This works perfectly except for one thing.
>
> If the word in the string has a any kind of punctuation after it
> (period,
> comma) it won't be matched.
>
> So if moron is an inappropriate word then "you are a moron" works,
> but "you
> are a moron." won't.
>
> Any ideas?
>
> Thanks
>
> This is my code.
>
> function badwords($string) {
>
> $language = array(contains the inappropriate words);
>
> $words = explode(" ",$string);
> $count = count(explode(" ", $string));
>
> for($i = 0; $i < $count; $i++) {
> if(in_array(strtolower($words[$i]), $language)) {
> $words[$i] = "*****";
> }
> }
>
> $newcomments = join(" ",$words);
>
> return $newcomments;
> }
>
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
I have been writing some code that visits each directory stored within one
directory in turn, pics a random image from it and displays that image.
I have the code working fine, apart from one small quirk that I can't really
understand.
In one version of the implementation, the directories appear to be getting
accessed in the order they are uploaded to / edited on the server starting
with the most recent upload/change - which is handy because it is what I
wanted.
But in another slightly different version of the same bit of code, it lists
them in some weird order that I can't fathom.
I suppose my question put simply is, what is the default ordering of
directories when PHP uses the readdir method? And is there anyway to force a
specific ordering to the directories before PHP searches down them?
Any help would be greatly appreciated.
Regards,
Toby
--- End Message ---
--- Begin Message ---
According to php.net, the readdir() function simply reads the contents of
the directory in the order which they are stored by the filesystem.
One way to force the order would be to loop through the contents of the
directory and store the directory names into an array, and use the functions
filemtime() and sort() to sort the array.
Hope that helps,
Brad
-----Original Message-----
From: Toby Osbourn [mailto:[EMAIL PROTECTED]
Sent: Friday, September 15, 2006 3:18 PM
To: php-general@lists.php.net
Subject: [PHP] readdir
I have been writing some code that visits each directory stored within one
directory in turn, pics a random image from it and displays that image.
I have the code working fine, apart from one small quirk that I can't really
understand.
In one version of the implementation, the directories appear to be getting
accessed in the order they are uploaded to / edited on the server starting
with the most recent upload/change - which is handy because it is what I
wanted.
But in another slightly different version of the same bit of code, it lists
them in some weird order that I can't fathom.
I suppose my question put simply is, what is the default ordering of
directories when PHP uses the readdir method? And is there anyway to force a
specific ordering to the directories before PHP searches down them?
Any help would be greatly appreciated.
Regards,
Toby
--- End Message ---
--- Begin Message ---
On Fri, September 15, 2006 2:18 pm, Toby Osbourn wrote:
> I suppose my question put simply is, what is the default ordering of
> directories when PHP uses the readdir method?
Whatever order the OS decides to use.
In practice, it's whatever is convenient for that particular file system.
So FAT, NFTS, Reiser, ext2, ext3, and so on could all behave differently.
For that matter, the OS could decide to randomize them, just for fun,
if it wanted to.
> And is there anyway to
> force a
> specific ordering to the directories before PHP searches down them?
Not with just opendir/readdir.
You could use exec() with "ls" to get them in various orders.
You could walk through and make an array and then sort.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
On Friday 15 September 2006 14:18, Toby Osbourn wrote:
> I suppose my question put simply is, what is the default ordering of
> directories when PHP uses the readdir method? And is there anyway to force
> a specific ordering to the directories before PHP searches down them?
If you're on PHP 5, look at scandir(). It gives you an array of all of the
files/directories in a given directory, which you can then sort with sort()
or usort() or whatever. If you're on PHP 4, there's a backport of it in
PEAR::PHP_Compat that doesn't actually require the rest of PEAR to
function. :-)
--
Larry Garfield AIM: LOLG42
[EMAIL PROTECTED] ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
--- End Message ---
--- Begin Message ---
Hello all,
Again a question on the new DOM functions...
The loadHTML function doesn't support any attribute and I'm wondering how to
handle non-text content. Image tags from source webpage are loaded as "objects"
or whatever; they appear as special chars("show source" from browser shows big
empty spaces)... Isn't it possible to "load" the real source code? Special
characters, like the german "ä" is also badly converted into some bizarr "ä"
equivalent...
I tried both functions loadHTML($string) ($string = file_gets_content(url)) and
loadHTMLFile(url). Both with the same result...
Has anyone an idea how to do it?
Thanks
LS
--
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
--- End Message ---
--- Begin Message ---
How are you getting that output?
Remember most of the functionality - other than the saveXML(),
saveHTML() functions - output using UTF-8 (which you would need to
convert to what ever encoding you need).
Rob
Leonidas Safran wrote:
Hello all,
Again a question on the new DOM functions...
The loadHTML function doesn't support any attribute and I'm wondering how to handle non-text content. Image tags from source
webpage are loaded as "objects" or whatever; they appear as special chars("show source" from browser shows
big empty spaces)... Isn't it possible to "load" the real source code? Special characters, like the german
"ä" is also badly converted into some bizarr "ä" equivalent...
I tried both functions loadHTML($string) ($string = file_gets_content(url)) and
loadHTMLFile(url). Both with the same result...
Has anyone an idea how to do it?
Thanks
LS
--- End Message ---
--- Begin Message ---
Hello Rob,
Thanks for answering (so fast)... :-)
> Remember most of the functionality - other than the saveXML(),
> saveHTML() functions - output using UTF-8
> (which you would need to convert to what ever encoding you need).
Well I did try before loadHTML call:
$doc = new DomDocument('1.0', 'iso-8859-1');
Maybe it's a problem that the source webpage I'm loading has no charset
declaration. It solely uses:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="de" xmlns="http://www.w3.org/1999/xhtml">
Don't know if that has an influence...
> How are you getting that output?
About the output I make, I don't use the saveHTML function because I just cut
some parts of the source (grabbed with getElementById() and other related
functions) and only need them, so I just "echo" them into a new document.
LS
--
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
--- End Message ---
--- Begin Message ---
Is there a meta tag that specifies the encoding? When loading HTML that
is also used to determine the encoding. I think I need to clarify the
encoding issue:
I'll bet when the document is loading, the encoding is being properly
detected. When working with the elements however you are getting hung up
on the UTF-8 factor....
you probably do something like the following:
$myelement = getElementById('someid');
print $myelement->textContent;
That right there will output the textual content in UTF-8 (the garbled
characters). It does not take into consideration the encoding used in
the origional document. This is just how the xml functions work. Now...
You really need to do something like:
$text = $myelement->textContent;
print iconv("UTF-8", <output encoding>, $text);
If the encoding is in the meta tag, typically encountered as:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
If you add the content to a dom node, you do not change the encoding
since the functions all work on UTF-8. The document to which the content
is being added however, must be set to use the desired encoding. I am
assuming you are doing what I previously explained though.
Rob
Leonidas Safran wrote:
Hello Rob,
Thanks for answering (so fast)... :-)
Remember most of the functionality - other than the saveXML(),
saveHTML() functions - output using UTF-8
(which you would need to convert to what ever encoding you need).
Well I did try before loadHTML call:
$doc = new DomDocument('1.0', 'iso-8859-1');
This does nothing. loadHTML() causes a new underlying document and
replaces the one you created with the new DOMDocument() call. That is
only pertinant when you are manually building a document.
Maybe it's a problem that the source webpage I'm loading has no charset
declaration. It solely uses:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="de" xmlns="http://www.w3.org/1999/xhtml">
Don't know if that has an influence...
How are you getting that output?
About the output I make, I don't use the saveHTML function because I just cut some parts
of the source (grabbed with getElementById() and other related functions) and only need
them, so I just "echo" them into a new document.
LS
--- End Message ---
--- Begin Message ---
Is there a meta tag that specifies the encoding? When loading HTML that
is also used to determine the encoding. I think I need to clarify the
encoding issue:
I'll bet when the document is loading, the encoding is being properly
detected. When working with the elements however you are getting hung up
on the UTF-8 factor....
you probably do something like the following:
$myelement = getElementById('someid');
print $myelement->textContent;
That right there will output the textual content in UTF-8 (the garbled
characters). It does not take into consideration the encoding used in
the origional document. This is just how the xml functions work. Now...
You really need to do something like:
$text = $myelement->textContent;
print iconv("UTF-8", <output encoding>, $text);
If the encoding is in the meta tag, typically encountered as:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
If you add the content to a dom node, you do not change the encoding
since the functions all work on UTF-8. The document to which the content
is being added however, must be set to use the desired encoding. I am
assuming you are doing what I previously explained though.
Rob
Leonidas Safran wrote:
Hello Rob,
Thanks for answering (so fast)... :-)
Remember most of the functionality - other than the saveXML(),
saveHTML() functions - output using UTF-8
(which you would need to convert to what ever encoding you need).
Well I did try before loadHTML call:
$doc = new DomDocument('1.0', 'iso-8859-1');
This does nothing. loadHTML() causes a new underlying document and
replaces the one you created with the new DOMDocument() call. That is
only pertinant when you are manually building a document.
Maybe it's a problem that the source webpage I'm loading has no charset
declaration. It solely uses:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="de" xmlns="http://www.w3.org/1999/xhtml">
Don't know if that has an influence...
How are you getting that output?
About the output I make, I don't use the saveHTML function because I just cut some parts
of the source (grabbed with getElementById() and other related functions) and only need
them, so I just "echo" them into a new document.
LS
--- End Message ---
--- Begin Message ---
2006/9/14, Norbert Wenzel <[EMAIL PROTECTED]>:
Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [...] Y Z AA AB AC [...] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
thanks,
Norbert
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
http://marc.theaimsgroup.com/?t=114944281100002
--- End Message ---
--- Begin Message ---
On Wed, September 13, 2006 5:56 am, Dave Goodchild wrote:
> Hi all. I am building an online events registry and have mapped out
> all the
> dates between Oct 1 2006 and Dec 31 2030, stored in the database as
> timestamps incremented by 86400 to give daily slots. I have output the
> values using the php date function and all is well. Users can enter
> either
> one-off or regular events, and I am using a mapping table to tie
> events to
> dates as they comprise a many-to-many relationship.
If I'm reading this correctly, you've created a table of every single
date, just to provide a JOIN table of massive proportions?
That's... Not Good (tm) almost for sure...
> I am struggling with some date conversions, however. When a user
> enters a
> single event for example, the data is entered into the events table,
> the
> inserted id captured, and then the system will look for the relevant
> record
> in the dates table, and eventually enter the event id and date id into
> the
> mapping table for later joins during the search process.
Now it sounds like you are inserting even MORE entries into another
table to make an even more confusing JOIN...
> To do this, I call:
>
> $date_string =
> mktime(0,0,0,$_SESSION['month],$_SESSION['day'],$_SESSION['year'])
>
> to assemble a timestamp from the supplied user data, and now I need to
> look
> for the matching date in the dates table. My problem is in converting
> between UNIX and mySQL timestamp values. My first attempt to match
> used this
> (query extract):
>
> "SELECT id FROM dates WHERE FROM_UNIXTIME($date_string) = date"
"SELECT id FROM dates WHERE date = '$month/$day/$year'"
has always worked for me...
If date is a timestamp or datetime, you have to convert THAT to a
date, so that the hours:minutes:seconds don't mess you up.
You're making all of this way too hard ... :-)
Re-think the concept of having a row for every possible day.
Just make sure all your tests for date equality are using the same
type of data -- DATE, not DATETIME, TIMESTAMP, etc.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
On Wed, September 13, 2006 12:58 am, Peter Lauri wrote:
> What should I do if they do not allow cookies? I could amend a=1234
> onto
> every url that they pass, but that would not be a "beautiful"
> solution.
PHP's use transsid setting in php.ini does exactly that, only with the
session ID, and you don't have to do nothing except turn it on. :-)
> Maybe I can also create a SESSION that stores the affiliate
> information so
> that it at least get registered if the purchase is completed within
> the
> session?
Using PHP SESSION with the transsid "on" means you can have the
session last reliably for up to 2 years, if you want to.
That's what I would do, personally, and then you can simplify your
code quite a bit...
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
The user contributed notes on php.net for str_replace has several
solutions...
On Tue, September 12, 2006 5:02 pm, Kevin Murphy wrote:
> I have a web form where trusted people will be inputing information
> that they usually copy/paste out of MS Word. While the people are
> trusted... MS Word isn't. I keep getting garbage characters in there,
> usually associated with Smart Quotes. If I take the content out of
> the DB, throw it into BBEdit and use the convert to ASCII command
> that solves the problem.
>
> Is there some way I can filter/convert this information before it
> gets to the mysql database?
>
>
> --
> Kevin Murphy
> Webmaster: Information and Marketing Services
> Western Nevada Community College
> www.wncc.edu
> 775-445-3326
>
>
>
>
> --
> Kevin Murphy
> Webmaster: Information and Marketing Services
> Western Nevada Community College
> www.wncc.edu
> 775-445-3326
>
>
>
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
See if "/Volumes" exists.
Then if "/Volumes/foresight" exists.
Then iterate through each with opendir/readdir and see what's in there.
Eventually, you will probably stumble over the issue...
Like, maybe you have permissions on the share, but not the file, or ...
On Tue, September 12, 2006 4:41 pm, Rahul S. Johari wrote:
>
> Permissions have been set on the Windows Server for the Mac user...
> And all
> permissions have been given to him.
>
> This is my code..
>
> <?php
> #Check is DBF Exists
> $filename = "/Volumes/foresight/2qc0831.dbf";
> if (file_exists($filename)) {
> echo "<br><br>$filename exists";
> } else {
> echo "<br><br>The file $filename does not exist";
> }
> ?>
> <br><br><br>
> <?
> #OPEN DBF FILE - READ ONLY
> $db = dbase_open("/Volumes/foresight/2qc0831.dbf", 0);
> if ($db) {
> $record_numbers = dbase_numrecords($db);
> for ($i = 1; $i <= $record_numbers; $i++) {
> $row = dbase_get_record_with_names($db, $i);
> if ($row['PHONE'] == $thekey) {
> ?>
>
>
>
> On 9/12/06 5:37 PM, "Ray Hauge" <[EMAIL PROTECTED]>
> wrote:
>
>> On Tuesday 12 September 2006 16:27, Rahul S. Johari wrote:
>>> Ave,
>>>
>>> I©öm getting really frustrated with this. How do I get PHP to
>>> open/read a
>>> file which is on a Share, mounted on Mac OS X.
>>>
>>> My Mac OS X is connected to a Windows 2003 Server... A Shared
>>> Folder
>>> remains mounted on my Mac OS X and I need PHP to read a file off
>>> that
>>> share. But it won©öt! I just can©öt get the path to work!!
>>>
>>> I©öve tried ©ø/Volumes/Server/file.dbf©÷ ..... I©öve tried to
>>> create Aliases
>>> (shortcuts)... But nothing seems to work! What©ös the trick? How
>>> can I get
>>> this to work? Any suggestions?
>>>
>>> Rahul S. Johari
>>> Supervisor, Internet & Administration
>>> Informed Marketing Services Inc.
>>> 500 Federal Street, Suite 201
>>> Troy NY 12180
>>>
>>> Tel: (518) 687-6700 x154
>>> Fax: (518) 687-6799
>>> Email: [EMAIL PROTECTED]
>>> http://www.informed-sources.com
>>
>> First I would check to make sure that permissions are set correctly.
>> PHP
>> doesn't (necessarily) run under your user account. Other than that
>> I have no
>> idea.
>>
>> HTH
>
> Rahul S. Johari
> Supervisor, Internet & Administration
> Informed Marketing Services Inc.
> 500 Federal Street, Suite 201
> Troy NY 12180
>
> Tel: (518) 687-6700 x154
> Fax: (518) 687-6799
> Email: [EMAIL PROTECTED]
> http://www.informed-sources.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
Hehe, you gave me some pretty good ideas to make my code sit
safely elsewhere and leave them wondering where the entire site is
coming from. Even if i dont get anything done remotely, at least i
learned some nice things from you guys, so thanks anyway.
And i love my job...although i get paid miserably.:-P (oh,
and the college i work at is practically an all-girls college...so at
least the view is always nice..ahem)
Again, big thanks.
Pag
At 19:35 15-09-2006, Richard Lynch wrote:
Errrr.
Now, instead of just the arrogant leaches [sic] in your department,
college, etc, you have opened up your code to the ENTIRE WORLD of
arrogant leaches to steal...
I don't think this is what you want...
Maybe just find a new job. :-)
--- End Message ---
--- Begin Message ---
Please try below page/program on your system entering "ab-cd" and
please tell me I dont know regex - because the way I see it the
results of those tests should have been the same...
-----------------------------------------------------------------------
<html><body><form method=post action=<?php $PHP_SELF ?>
Please enter something with a dash here: <input type='text'
name='regex_test' />
<input type='submit' value='Submit' />
</form>
<?php
if (isset($_REQUEST['regex_test'])) {
print "Testing ".$_REQUEST['regex_test'].' with regex
/^[A-Za-z0-9\._\-]{3,63}$/ ... :';
if (ereg("^[A-Za-z0-9\._\-]{3,63}$",$_REQUEST['regex_test'])) print " Ok";
else print " Nak";
print "<br /><br />";
print "Testing ".$_REQUEST['regex_test'].' with regex
/^[A-Za-z0-9\.\-_]{3,63}$/ ... :';
if (ereg("^[A-Za-z0-9\.\-_]{3,63}$",$_REQUEST['regex_test'])) print " Ok";
else print " Nak";
}
print "<br /><br />Current PHP Version is: ".phpversion();
?>
</body></html>
--- End Message ---
--- Begin Message ---
Hi all. I have a session issue and wondered if anyone else has encountered
this:
I have an app where a user fills out 3 forms. In each case, after validation
and cleaning the form data is passed into session variables and after the
final submission the data is entered into the database. I am using both
Firefox and IE6 on Windows XP and the system works like a dream. However, a
user testing on IE6/XP is having some problems. The values from the first
form are not being passed into the session.
When each form is successfully processed the user is redirected to the next
stage using header('Location...'). I call session_write_close before that to
ensure the session data is written out before the redirect, but the problem
persists.
Anyone recognise this issue. It is not IE-specific as it happens to me on
Firefox intermittently. I am at my wits end! Thanks in advance for any help!
--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk
--- End Message ---