php-general Digest 28 Jun 2007 23:24:14 -0000 Issue 4874
Topics (messages 257905 through 257925):
Re: FreeMovie API
257905 by: Tijnema
Re: Swear filter ideas
257906 by: Tijnema
257907 by: Steve Edberg
257908 by: Robert Cummings
257914 by: Colin Guthrie
257915 by: Daniel Brown
257916 by: Daniel Brown
257918 by: Robert Cummings
257921 by: Colin Guthrie
257922 by: Jochem Maas
257923 by: Daniel Brown
Include images in php file
257909 by: Marek
257910 by: Stut
257911 by: Jochem Maas
257912 by: Marek
257913 by: Robert Cummings
257917 by: Marek
257919 by: Jim Moseby
257920 by: Jochem Maas
Re: strange include path error
257924 by: Jim Lucas
257925 by: brian
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:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
On 6/27/07, David Giragosian <[EMAIL PROTECTED]> wrote:
Anyone using or know the status of the FreeMovie PHP toolkit?
Seems like development stopped in 2004...
David
From sourceforge news:
"I am finishing work on a new version of FreeMovie. It will be
properly documented and there will be a printed developer's guide.
Stay tuned for news at devGuide.net "
Tijnema
--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
--- End Message ---
--- Begin Message ---
On 6/28/07, Richard Davey <[EMAIL PROTECTED]> wrote:
Hi all,
Just wanting to pick your collective brains on this one:
How do you go about implementing a swear / bad-word filter in PHP?
Reasons for needing one aside, I'm just wondering if you favour a
regexp, a substr_count, or what? Do you like to *** out the bad words,
or just error back to the user? (I guess that is application
specific).
There are always ways to circumvent them, but I'm still curious to
know how you prefer to handle it.
Cheers,
Rich
This is a really though thing to implement, let's say you don't want
to the word "ass" in your message coming from the user, and the
message contains this:
Hi, in the archive I attached is a picture of my ass, the password is abcdef.
The word ass is not wanted, so you *** it, but if you do that with a
regexp or such, then password would become p***word, or you want to
check only for real words (so spaces on both sides), but then somebody
would write !ass! or something like that.
Tijnema
--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
--- End Message ---
--- Begin Message ---
At 12:35 PM +0200 6/28/07, Tijnema wrote:
On 6/28/07, Richard Davey <[EMAIL PROTECTED]> wrote:
Hi all,
Just wanting to pick your collective brains on this one:
How do you go about implementing a swear / bad-word filter in PHP?
Reasons for needing one aside, I'm just wondering if you favour a
regexp, a substr_count, or what? Do you like to *** out the bad words,
or just error back to the user? (I guess that is application
specific).
There are always ways to circumvent them, but I'm still curious to
know how you prefer to handle it.
Cheers,
Rich
This is a really though thing to implement, let's say you don't want
to the word "ass" in your message coming from the user, and the
message contains this:
Hi, in the archive I attached is a picture of my ass, the password is abcdef.
The word ass is not wanted, so you *** it, but if you do that with a
regexp or such, then password would become p***word, or you want to
check only for real words (so spaces on both sides), but then somebody
would write !ass! or something like that.
Something like that could be taken care of with a regexp like
$CleansedLine = preg_replace('/\bass\b/i', '***', $Line);
The \b matches a word boundary, i means case insensitive. You'd have
to loop through your BadWord list for each line:
foreach ($BadWords as $BW) {
$CleansedLine = preg_replace("/\b$BW\b/i", '***', $Line);
}
Your badword list should include variants like A55 for ASS, etc.
Recognize that you aren't going to aren't going to catch all the
alternatives, but this should get most of them. And of course, if
you're talking about donkeys, ass is legitimate :). If you really
need to filter all profanity the only solution I know of is
moderation. If you want to count the number of badwords and reject
based on reaching a certain threshold, you could do
$SwearCount = 0;
foreach ($BadWords as $BW) {
$SwearCount += preg_match_all("/\b$BW\b/i", $Line);
$CleansedLine = preg_replace("/\b$BW\b/i", '***', $Line);
}
# In PHP 5.1, apparently preg_replace can return a match count,
# eliminating the need for a separate preg_match_all
if ($SwearCount > SWEAR_THRESHOLD) {
echo 'You %$#&%@, who do you [EMAIL PROTECTED] think you [EMAIL
PROTECTED] are ??';
}
- st&[EMAIL PROTECTED]
--
+--------------- my people are the people of the dessert, ---------------+
| Steve Edberg http://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center [EMAIL PROTECTED] |
| Bioinformatics programming/database/sysadmin (530)754-9127 |
+---------------- said t e lawrence, picking up his fork ----------------+
--- End Message ---
--- Begin Message ---
On Thu, 2007-06-28 at 12:35 +0200, Tijnema wrote:
> On 6/28/07, Richard Davey <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > Just wanting to pick your collective brains on this one:
> >
> > How do you go about implementing a swear / bad-word filter in PHP?
> >
> > Reasons for needing one aside, I'm just wondering if you favour a
> > regexp, a substr_count, or what? Do you like to *** out the bad words,
> > or just error back to the user? (I guess that is application
> > specific).
> >
> > There are always ways to circumvent them, but I'm still curious to
> > know how you prefer to handle it.
> >
> > Cheers,
> >
> > Rich
>
> This is a really though thing to implement, let's say you don't want
> to the word "ass" in your message coming from the user, and the
> message contains this:
>
> Hi, in the archive I attached is a picture of my ass, the password is abcdef.
>
> The word ass is not wanted, so you *** it, but if you do that with a
> regexp or such, then password would become p***word, or you want to
> check only for real words (so spaces on both sides), but then somebody
> would write !ass! or something like that.
You got a problem with beasts of burden?
:)
Cheers,
Rob
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
Richard Davey wrote:
> Hi all,
>
> Just wanting to pick your collective brains on this one:
>
> How do you go about implementing a swear / bad-word filter in PHP?
>
> Reasons for needing one aside, I'm just wondering if you favour a
> regexp, a substr_count, or what? Do you like to *** out the bad words,
> or just error back to the user? (I guess that is application
> specific).
>
> There are always ways to circumvent them, but I'm still curious to
> know how you prefer to handle it.
We implemented a simple key => value array map of rude words to
"sanitised" equivalents:
e.g. breast => sandwich, felch => retrieve etc. etc.
Then we used implode to generate a regexp:
$new = ' '.$strBadWordsWrittenByEvilUser.' ';
$gStopRegexp = '('.implode('|',array("\n","\r",'
',',','\.',';',':','-','\!',"'",'"')).')';
foreach ($gNaughtyWords as $naughty=>$nice)
{
$regexp = $gStopRegexp.'('.$naughty.')([s]{0,1})'.$gStopRegexp;
$regexp_rep = '\1'.$nice.'\3\4';
$new = mb_eregi_replace($regexp, $regexp_rep, $new);
}
return trim($new);
The added bonus is that you can flip the key/values in your array and
turn perfectly nice sentences into torrents of abuse ;)
It's not perfect but it works for the most part. And it's fun to think
of all the rude words people might use!!
HTH
Col
--- End Message ---
--- Begin Message ---
On 6/28/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
You got a problem with beasts of burden?
No, we like you sometimes, Rob. ;-P
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
--- End Message ---
--- Begin Message ---
On 6/28/07, Colin Guthrie <[EMAIL PROTECTED]> wrote:
We implemented a simple key => value array map of rude words to
"sanitised" equivalents:
e.g. breast => sandwich, felch => retrieve etc. etc.
"Today we have Chicken Marsala over angel hair pasta, which is a
chicken sandwich braised in Marsala wine...."
"Please keep me asandwich of the events as they transpire."
The added bonus is that you can flip the key/values in your array and
turn perfectly nice sentences into torrents of abuse ;)
"Sandy was a golden felcher...."
It's not perfect but it works for the most part. And it's fun to think
of all the rude words people might use!!
We had a pretty decent thread on this about two weeks back, if
memory serves. Check the archives and you can make your corporate
firewall cry.
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
--- End Message ---
--- Begin Message ---
On Thu, 2007-06-28 at 10:06 -0400, Daniel Brown wrote:
> On 6/28/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> > You got a problem with beasts of burden?
>
> No, we like you sometimes, Rob. ;-P
You've been checking me out in the gym shower haven't you!! ;)
But seriously, that was a good one :)
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
Daniel Brown wrote:
> On 6/28/07, Colin Guthrie <[EMAIL PROTECTED]> wrote:
>> We implemented a simple key => value array map of rude words to
>> "sanitised" equivalents:
>>
>> e.g. breast => sandwich, felch => retrieve etc. etc.
>
> "Today we have Chicken Marsala over angel hair pasta, which is a
> chicken sandwich braised in Marsala wine...."
Indeed. Your word list would have to allow certain words that could be
used in genuine text. Other words which I wont post here would never be
used in general conversation ;)
> "Please keep me asandwich of the events as they transpire."
This one wouldn't happen due to the stop words regexp.
>> The added bonus is that you can flip the key/values in your array and
>> turn perfectly nice sentences into torrents of abuse ;)
>
> "Sandy was a golden felcher...."
Exactly! Awesome eh!?! Hours of fun!
Col.
--- End Message ---
--- Begin Message ---
Colin Guthrie wrote:
> Daniel Brown wrote:
>> On 6/28/07, Colin Guthrie <[EMAIL PROTECTED]> wrote:
>>> We implemented a simple key => value array map of rude words to
>>> "sanitised" equivalents:
>>>
>>> e.g. breast => sandwich, felch => retrieve etc. etc.
>> "Today we have Chicken Marsala over angel hair pasta, which is a
>> chicken sandwich braised in Marsala wine...."
>
> Indeed. Your word list would have to allow certain words that could be
> used in genuine text. Other words which I wont post here would never be
> used in general conversation ;)
unless the general was in the heat of combat, there the implied language
would probably be justified. :->
>
>> "Please keep me asandwich of the events as they transpire."
>
> This one wouldn't happen due to the stop words regexp.
>
>>> The added bonus is that you can flip the key/values in your array and
>>> turn perfectly nice sentences into torrents of abuse ;)
>> "Sandy was a golden felcher...."
^-- this 'e' shouldn't be there according to the
amp given above.
which means Sandy is not only on the cutting edge of porn, but also
web2.0 ready :-P
[think flickr] ... which begs the question of what to do with
multilingual situations. one languages' mundane word can be another's
rudest addition (dutch has a phonetically indentical word for 'flicker'
which has altogether different connotations than it does in english)
maybe we should all just shut the **** up on a global level ... it is
said that silence is golden (which is a condrum of itself, what with it
be said and all)
>
> Exactly! Awesome eh!?! Hours of fun!
nothing like a little be of mind bending with words eh :-)
>
> Col.
>
--- End Message ---
--- Begin Message ---
On 6/28/07, Colin Guthrie <[EMAIL PROTECTED]> wrote:
Daniel Brown wrote:
> On 6/28/07, Colin Guthrie <[EMAIL PROTECTED]> wrote:
>> We implemented a simple key => value array map of rude words to
>> "sanitised" equivalents:
>>
>> e.g. breast => sandwich, felch => retrieve etc. etc.
>
> "Today we have Chicken Marsala over angel hair pasta, which is a
> chicken sandwich braised in Marsala wine...."
Indeed. Your word list would have to allow certain words that could be
used in genuine text. Other words which I wont post here would never be
used in general conversation ;)
That's for fucking sure.
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
--- End Message ---
--- Begin Message ---
Hi,
I want to display images with my php script but i want it to be just ONE
file. I can't have separate image files or folders etc.
I suppose I could get this result by writing a function that generates
the right image by drawing it from scratch. But that way I can't have
any photos.
My question: Is there any way to include an entire jpg/gif/png into a
php file? So that when i call ?pic=myphoto it can present the right
photo without a database or additional files. Like a serialized form of
an image or something that can be copied, saved in a text editor and
later reassembled as a proper photo.
Thanks for your help.
Marek
--- End Message ---
--- Begin Message ---
Marek wrote:
I want to display images with my php script but i want it to be just ONE
file. I can't have separate image files or folders etc.
Why not? This seems like a rather daft limitation.
I suppose I could get this result by writing a function that generates
the right image by drawing it from scratch. But that way I can't have
any photos.
My question: Is there any way to include an entire jpg/gif/png into a
php file? So that when i call ?pic=myphoto it can present the right
photo without a database or additional files. Like a serialized form of
an image or something that can be copied, saved in a text editor and
later reassembled as a proper photo.
You could base64_encode the image data and stick it in a string.
However, by doing this you will be causing huge memory usage whenever
teh script is used because PHP will allocate the memory required for
each embedded image even when you are only going to use one.
Put simply, it's a rediculous way to approach the problem. I suggest you
explain why there is this restriction - there may be a better way to do it.
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
Marek wrote:
> Hi,
>
> I want to display images with my php script but i want it to be just ONE
> file. I can't have separate image files or folders etc.
>
> I suppose I could get this result by writing a function that generates
> the right image by drawing it from scratch. But that way I can't have
> any photos.
>
> My question: Is there any way to include an entire jpg/gif/png into a
> php file? So that when i call ?pic=myphoto it can present the right
> photo without a database or additional files. Like a serialized form of
> an image or something that can be copied, saved in a text editor and
> later reassembled as a proper photo.
yes. well done for taking the time to search:
http://dean.edwards.name/weblog/2005/06/base64-sexy/
http://www.greywyvern.com/code/php/binary2base64
http://php.net/base64_encode <-- 4th comment
>
> Thanks for your help.
> Marek
>
--- End Message ---
--- Begin Message ---
It's not really a limitation but a personal goal.
I develop a small public script that is meant to be very compact and
portable. All of its functionality fits nicely in one php file. But at
the moment it requires a bunch of tiny icons. I would like to eliminate
this and just have a single file. But without ruining the graphical
interface.
So far the best solution i just came up with is to have two files - one
would be an image with all the icons and i could use css to display the
right icon.
Marek
--- End Message ---
--- Begin Message ---
On Thu, 2007-06-28 at 16:39 +0300, Marek wrote:
> It's not really a limitation but a personal goal.
>
> I develop a small public script that is meant to be very compact and
> portable. All of its functionality fits nicely in one php file. But at
> the moment it requires a bunch of tiny icons. I would like to eliminate
> this and just have a single file. But without ruining the graphical
> interface.
>
> So far the best solution i just came up with is to have two files - one
> would be an image with all the icons and i could use css to display the
> right icon.
Usually compactness is achieved by having one directory in which all
your files reside. Having everything embedded in one php file (images
and everything) is ridiculous. But as other have said you can base64
encode your images and embed them directly into the source and use a get
parameter to select them when accessing the page. So the page would
produce HTML that calls the same page with different parameters for the
images. Same as you're no doubt already doing... front end loader
pattern.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
> yes. well done for taking the time to search:
And thank you for those links and a lovely sarcastic comment.
If i had known to search for "base64", i would not have asked, really.
Other keywords like "image in php jpg gif png include embed serialize"
in various combinations didn't give any useful results.
Thank you, i now got my answer - it can be done but at the cost of high
memory usage. And i don't think i'll be using it. But the idea itself
isn't really that bad. If you have a small script that you often copy,
move and delete, it is more handy to have just one file instead of a
folder system. I know it would be oscure to the programmer but
convenient for the user.
Marek
--- End Message ---
--- Begin Message ---
<snip>
>...it is more handy to have just one file instead of a
> folder system.
Thats why $deity gave us gzip. ;-)
--- End Message ---
--- Begin Message ---
Jim Moseby wrote:
> <snip>
>> ...it is more handy to have just one file instead of a
>> folder system.
>
> Thats why $deity gave us gzip. ;-)
>
whihc makes me think ...
maybe the phar extension could be a good option?
--- End Message ---
--- Begin Message ---
brian wrote:
Greg Beaver wrote:
brian wrote:
PHP 5.1.4 on Fedora 2
I recieved a note from a client about a problem with their site today.
Looking at the error log, i found that the DB connection script that's
included into any other that needs it was throwing an error because
MDB2.php couldn't be found:
Failed opening required 'MDB2.php'
(include_path='.:/opt/www/zijn2/htdocs/includes:/usr/local/lib/php')
What's *really* weird is that the paths listed there are
ancient--everything is in /usr/share/pear now, and the zijn2 one had
been added--then removed--when i was troubleshooting something (it seems
like a couple of years ago).
Do a grep for "set_include_path" in your client's code - I suspect
you'll find it.
Nope. I wrote the app and i have no need for set_include_path, in any
case, as i control the server. I did also doublecheck the vhost conf but
there's nothing there. This is the thing: it's *my* code and i can't
think of anything that would cause this.
I've also ensured that there's only one php.ini on the server. Apache
has been restarted several times since that old include path existed.
This is why i was talking about the box being rebooted, as well. I'm
trying to cover everything but i'm flummoxed.
FWIW, i've also carefully gone over the site and everything seems to be
in order. The error was triggered when some script included a DB
connection script (that has "require_once 'MDB2.php';") but,
unfortunately, the error msg doesn't specify which it was.
I guess i'll have to wait until tuesday to get more info from the client.
brian
you could always cross reference the time stamp in the error log to the access
log and see what matches.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
brian wrote:
FWIW, i've also carefully gone over the site and everything seems to
be in order. The error was triggered when some script included a DB
connection script (that has "require_once 'MDB2.php';") but,
unfortunately, the error msg doesn't specify which it was.
I guess i'll have to wait until tuesday to get more info from the client.
brian
you could always cross reference the time stamp in the error log to the
access log and see what matches.
D'OH! I guess that's why $deity created mailing lists--to allow us all
to make boobs of ourselves once in a while.
I saw the same error again twice today and have found the two seperate
scripts that were called (incidentally, the clients were the google &
yahoo bots). Neither script shows me anything odd and i've checked every
other script included within them.
It's like there's a rogue thread or something. Except the box has been
rebooted at least once since i upgraded, which is when i changed the
include path location.
brian
--- End Message ---