php-general Digest 26 Oct 2008 23:43:23 -0000 Issue 5757

Topics (messages 282437 through 282459):

Re: Replacing with f*ck and f*cking
        282437 by: Maciek Sokolewicz
        282438 by: Colin Guthrie
        282439 by: Ashley Sheridan
        282441 by: Dotan Cohen
        282457 by: Larry Garfield

Re: Interactive canvas example
        282440 by: Nick Stinemates
        282442 by: Yeti
        282443 by: Richard Heyes
        282446 by: Shawn McKenzie
        282448 by: Yeti
        282450 by: tedd
        282451 by: Richard Heyes
        282452 by: Richard Heyes
        282453 by: Richard Heyes
        282454 by: Richard Heyes
        282456 by: Richard Heyes

PHP XSLT caching
        282444 by: vladimirn
        282447 by: Colin Guthrie
        282449 by: vladimirn
        282455 by: Colin Guthrie
        282458 by: Per Jessen

Re: PHP/mySQL question using ORDER BY with logic
        282445 by: Carlos Medina

Re: clear a mysql table
        282459 by: Chris

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 ---
Ryan S wrote:
Hey!
I'm just trying to replace some of the more bad words with their slightly 
censored counterparts like so

$bad_words = array(/*Well you know the words so am not going to write them 
here*/);
$bad_words_replacements = array("f*ck", "f*cking");
$comment = str_replace("$bad_words",$bad_words_replacements,  $comment);

My question is this, for just two words its fine to use the above, but a pal 
tells me that if using a lot of words (eg: 15) and the $comment is big then it 
can take quite some time and be a bit of a processing strain as well because 
php first checks the first word from the good list against all the 15 words in 
the bad list against the comment then moves to the second word etc.
The above isn't fine since it will never work. The reason for that is the fact that you enclose your array in quotes. This is something I've never understood, I've seen tons of people do it, and to me it looks like someone doesn't have a CLUE what he's doing. Why am I ranting about this? This is why:

$some_string = 'this used to be an a, but is now also a b';
$bad_words = array('a','b');
echo str_replace("$bad_words", 'something else', $some_string);

What does this mean ? If you remove all variables, you'll get:
echo str_replace('array', 'O', 'this used to be an a, but is now also a b');
And the result you'll get:
this used to be an a, but is now also a b

However, leaving away the quotes, since they're useless around a single variable anyway (what, don't you think PHP knows the variable is a string without you adding quotes around it?), like so: echo str_replace(array('a','b'), 'O', 'this used to be an a, but is now also a b');
you'll get:
this used to Oe On O, Out is now Olso O O

Hmm, there's a difference! :o

- Tul
P.S. IMO people should never write "$var", if they REALLY want to cast it to a string, do it explicitly like so: (string) $var; it keeps things obvious and simple, not to mention working.
--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
What you really need to watch out for is words which you're going to
censor which might be part of other names. Sex is an obvious one, as it
appeared in the borough name of my old address: Middlesex.

I can't believe you didn't use the infamous "Scunthorpe" as your example :p

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
On Sun, 2008-10-26 at 11:06 +0000, Colin Guthrie wrote:
> Ashley Sheridan wrote:
> > What you really need to watch out for is words which you're going to
> > censor which might be part of other names. Sex is an obvious one, as it
> > appeared in the borough name of my old address: Middlesex.
> 
> I can't believe you didn't use the infamous "Scunthorpe" as your example :p
> 
> Col
> 
> 
> -- 
> 
> Colin Guthrie
> gmane(at)colin.guthr.ie
> http://colin.guthr.ie/
> 
> Day Job:
>    Tribalogic Limited [http://www.tribalogic.net/]
> Open Source:
>    Mandriva Linux Contributor [http://www.mandriva.com/]
>    PulseAudio Hacker [http://www.pulseaudio.org/]
>    Trac Hacker [http://trac.edgewall.org/]
> 
> 
I forgot about that one to be honest. I did have a friend whose last
name is Hancock though, and I remember she had a lot of problems trying
to register for a hotmail email address!


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
2008/10/26 Colin Guthrie <[EMAIL PROTECTED]>:
> Ashley Sheridan wrote:
>>
>> What you really need to watch out for is words which you're going to
>> censor which might be part of other names. Sex is an obvious one, as it
>> appeared in the borough name of my old address: Middlesex.
>
> I can't believe you didn't use the infamous "Scunthorpe" as your example :p
>
> Col

There was a post on Coding Horror not long ago that brought this one up:
http://google.com/search?q=consbreastution

http://www.codinghorror.com/blog/archives/001176.html

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

ä-ö-ü-ß-Ä-Ö-Ü

--- End Message ---
--- Begin Message ---
On Sunday 26 October 2008 5:06:09 am Ashley Sheridan wrote:

> Obviously, this list could get pretty comprehensive, so like Andrew
> said, maybe you should look to see how some of the open source projects
> do it.
>
>
> Ash
> www.ashleysheridan.co.uk

The way Drupal handles such filtering is simple caching.  As a policy we never 
filter general content on save, because we may want to change the filter 
format later and destroying user-submitted data is *not cool*.  However, we 
do apply a number of possible filters on display (add line breaks, convert 
URLs to clickable, do "bad word" filtering, or any number of other things) 
and then just cache the result.  The cache lookup (based on a hash of the 
string being filtered and the ID of the filter set to apply) is far faster 
than reapplying the filters every time.  We've found this mechanism to scale 
very well.

-- 
Larry Garfield
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
On Sun, Oct 26, 2008 at 10:57:19AM +0000, Richard Heyes wrote:
> Hi,
> 
> Had to show this off - I'm so proud. READ: full of myself... I've
> tried it in Firefox 3, Opera 9.6, Chrome and Safari, all on Windows.
> 
> http://dev.rgraph.org/examples/interactive.html
> 
> -- 
> Richard Heyes
> 
> HTML5 Graphing for FF, Chrome, Opera and Safari:

Clicked a bar, nothing happened.

Google Chrome, Windows XP

--- End Message ---
--- Begin Message ---
It worked for me. Although I had some quite CPU intensive processes
running, so it lagged a bit.
Had no time to look into the code, so I was wondering if you could
answer my question ...
That yellow information box popping up onclick(), is it drawn by JS or
is it something like a hidden div?

Congratulations on that one
//A yeti

--- End Message ---
--- Begin Message ---
> It worked for me. Although I had some quite CPU intensive processes
> running, so it lagged a bit.
> Had no time to look into the code, so I was wondering if you could
> answer my question ...
> That yellow information box popping up onclick(), is it drawn by JS or
> is it something like a hidden div?

JS I suppose. Though it creates a DIV element on demand. The function
in question is RGraph.Tooltip() in RGraph.common.js.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)

--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
> Hi,
> 
> Had to show this off - I'm so proud. READ: full of myself... I've
> tried it in Firefox 3, Opera 9.6, Chrome and Safari, all on Windows.
> 
> http://dev.rgraph.org/examples/interactive.html
> 
Very nice.  Looks good on Kubuntu FF3.  The only issue I see is that no
matter which bar I click on, it says "January 2007 Sales: 80%", which
may just be your example, but I would think each bar should be different.

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
>JS I suppose. Though it creates a DIV element on demand. The function
>in question is RGraph.Tooltip() in RGraph.common.js.

OK, I found it. Thank you for showing me. I was thinking of something
similar recently.

/**
* Shows a tooltip next to the mouse pointer
*
* @param text The tooltip text
* @return     The tooltip object - a DIV
*/
RGraph.Tooltip = function (canvas, text, x, y)
{
        /**
        * Hide any currently shown tooltip
        */
        if (RGraph.tooltip) {
                RGraph.tooltip.style.display = 'none';
                RGraph.tooltip = null;
        }

        /**
        * Show a tool tip
        */
        var obj  = document.createElement('DIV');
        obj.style.position        = 'absolute'
        obj.style.backgroundColor = '#FFFFE1';
        obj.style.border          = '1px solid #333';
        obj.style.borderRight     = '2px solid #333';  // Set the right and
bottom borders to be a little thicker - gives the effect of a drop
shadow
        obj.style.borderBottom    = '2px solid #333'; // Set the right and
bottom borders to be a little thicker - gives the effect of a drop
shadow
        obj.style.display         = 'block'
        obj.style.visibility      = 'visible';
        obj.style.paddingLeft     = '3px';
        obj.style.paddingRight    = '3px';
        obj.style.fontFamily      = 'Tahoma';
        obj.style.fontSize        = '10pt';
        obj.innerHTML             = text;

        document.body.insertBefore(obj, canvas);

        obj.style.left            = (canvas.offsetLeft) + x + 3;
        obj.style.top             = (canvas.offsetTop + y) - obj.offsetHeight;
        
        /**
        * Install the function for hiding the tooltip.
        *
        * FIXME Not sure how this will affect any existing document.onclick 
event
        */
        document.body.onclick = function ()
        {
                RGraph.tooltip.style.display = 'none';
        }
        
        /**
        * Keep a reference to the object
        */
        RGraph.tooltip = obj;
}

Now I wonder why you are creating a new tooltip each time the user
clicks on the graph?
Why not do it the following way?

RGraph.Tooltip = function (canvas, text, x, y)
{
        try {
                if (RGraph.tooltip) { // if tooltip already drawn
                        RGraph.tooltip.innerHTML = text;
                        RGraph.tooltip.style.left = (canvas.offsetLeft) + x + 3;
                        RGraph.tooltip.style.top = (canvas.offsetTop + y) -
RGraph.tooltip.offsetHeight;
                } else { // create tooltip if not drawn yet
                        var obj  = document.createElement('DIV');
                        
                        obj.style.position        = 'absolute'
                        obj.style.backgroundColor = '#FFFFE1';
                        obj.style.border          = '1px solid #333';
                        obj.style.borderRight     = '2px solid #333';  // Set 
the right and
bottom borders to be a little thicker - gives the effect of a drop
shadow
                        obj.style.borderBottom    = '2px solid #333'; // Set 
the right and
bottom borders to be a little thicker - gives the effect of a drop
shadow
                        obj.style.display         = 'block'
                        obj.style.visibility      = 'visible';
                        obj.style.paddingLeft     = '3px';
                        obj.style.paddingRight    = '3px';
                        obj.style.fontFamily      = 'Tahoma';
                        obj.style.fontSize        = '10pt';
                        /*
                                //alternatively one could create a tooltip css 
class since this is
presentation
                                obj.className = 'tooltip'; //IE
                                obj.setAttribute('class', 'tooltip'); // W3C DOM
                        */
                        document.body.insertBefore(obj, canvas);
                        
                        RGraph.tooltip = obj;
                        
                        document.body.onclick = function ()
                        {
                                RGraph.tooltip.style.left = '-999'; //older 
opera fix
                        }
                        
                        return RGraph.Tooltip(canvas, text, x, y);
                }
                return RGraph.tooltip; // return tooltip obj as stated in 
functions comment
        } catch(e) {
                return false;   
        }
}

Secondly CanvasTextFunctions.letters() really is in a class of its own.
And why dont you use prototype [1]?

[1] http://www.w3schools.com/jsref/jsref_prototype_array.asp

//A yeti

--- End Message ---
--- Begin Message ---
At 10:57 AM +0000 10/26/08, Richard Heyes wrote:
Hi,

Had to show this off - I'm so proud. READ: full of myself... I've
tried it in Firefox 3, Opera 9.6, Chrome and Safari, all on Windows.

http://dev.rgraph.org/examples/interactive.html

--
Richard Heyes

Richard:

Very nice graph.

Instead of requiring the user to click, try using css and have it produce the details on roll-over, like so:

http://webbytedd.com/bbb/map/

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
> Very nice.  Looks good on Kubuntu FF3.  The only issue I see is that no
> matter which bar I click on, it says "January 2007 Sales: 80%", which
> may just be your example, but I would think each bar should be different.

Yes, I've still got to make an easy way to tie in differing tooltips.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)

--- End Message ---
--- Begin Message ---
> Now I wonder why you are creating a new tooltip each time the user
> clicks on the graph?

Why not? There's no need to cache it and it lessens the complexity if I don't.

> Why not do it the following way?

Which is?

> Secondly CanvasTextFunctions.letters() really is in a class of its own.


I didn't write it, I've just incorporated it into RGraph.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)

--- End Message ---
--- Begin Message ---
> Very nice graph.
>
> Instead of requiring the user to click, try using css and have it produce
> the details on roll-over, like so:

Hmm, should be as easy as changing the event from onclick to on
mouseover. I think. But yes, onmouseover would be far better.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)

--- End Message ---
--- Begin Message ---
> Hmm, should be as easy as changing the event from onclick to on
> mouseover. I think. But yes, onmouseover would be far better.

But it's not, since the mouse is already over the canvas when you move
it over a bar, thus not triggering a new event. Ho hum.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)

--- End Message ---
--- Begin Message ---
> ...

Ok, a little more playing and I've managed to whittle the public API
down, so animated bar charts galore!

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)

--- End Message ---
--- Begin Message ---
Hi all,
i was wondering whats the best approach to do next.
I have an xml file delivered from service of my partner. On my web server 
(windows) i have xslt files used for xml transformation. 
Those files are getting bigger, so i have request to cash them and use
cashed. I was thinkging about memcahce php(dunno if it will work on windows
server and tbh never used it before).
So i am sure that there must be several ways to cash xslt files. I google
for this, but i am not sure that i found any solution i can use.
What would be the best approach to solve this? I just would like to see more
ideas :)
LOL sure, if someone already have a good working solution i would appreciate
any link or code :0)
Greetings,
V
-- 
View this message in context: 
http://www.nabble.com/PHP-XSLT-caching-tp20173225p20173225.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---
vladimirn wrote:
Hi all,
i was wondering whats the best approach to do next.
I have an xml file delivered from service of my partner. On my web server (windows) i have xslt files used for xml transformation. Those files are getting bigger, so i have request to cash them and use
cashed. I was thinkging about memcahce php(dunno if it will work on windows
server and tbh never used it before).
So i am sure that there must be several ways to cash xslt files. I google
for this, but i am not sure that i found any solution i can use.
What would be the best approach to solve this? I just would like to see more
ideas :)
LOL sure, if someone already have a good working solution i would appreciate
any link or code :0)

Well you have to define what you actually want to do do here as it's a little unclear from your description.

Do you want to cache the XSLT files themselves or do you want to cache the result of *applying* the XSLT files to the input XML?

If you just want to cache the XSLT itself (e.g. loaded into a DOM document object) then there is little point as you would have to serialize and deserialize the dom document objects before storing them (via extending the class and adding __sleep() and __wakeup() methods) as I am pretty sure Dom Document doesn't do this automatically (last I checked which was admittedly a while ago!).

This only saves a small amount of overhead.

If you are looking for a good set of classes that can handle generic caching, I'd strongly recommend using the Zend_Cache system.
http://www.framework.zend.com/manual/en/zend.cache.html

Zend cache will support disk-based caching and memcache or APC too all via the same API.

Col





--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
Thank you Col
I will go into Zend_Cache as you suggested.
One more thing- does Zend_Cache saces data into file or use a server memory?

Colin Guthrie-6 wrote:
> 
> vladimirn wrote:
>> Hi all,
>> i was wondering whats the best approach to do next.
>> I have an xml file delivered from service of my partner. On my web server 
>> (windows) i have xslt files used for xml transformation. 
>> Those files are getting bigger, so i have request to cash them and use
>> cashed. I was thinkging about memcahce php(dunno if it will work on
>> windows
>> server and tbh never used it before).
>> So i am sure that there must be several ways to cash xslt files. I google
>> for this, but i am not sure that i found any solution i can use.
>> What would be the best approach to solve this? I just would like to see
>> more
>> ideas :)
>> LOL sure, if someone already have a good working solution i would
>> appreciate
>> any link or code :0)
> 
> Well you have to define what you actually want to do do here as it's a 
> little unclear from your description.
> 
> Do you want to cache the XSLT files themselves or do you want to cache 
> the result of *applying* the XSLT files to the input XML?
> 
> If you just want to cache the XSLT itself (e.g. loaded into a DOM 
> document object) then there is little point as you would have to 
> serialize and deserialize the dom document objects before storing them 
> (via extending the class and adding __sleep() and __wakeup() methods) as 
> I am pretty sure Dom Document doesn't do this automatically (last I 
> checked which was admittedly a while ago!).
> 
> This only saves a small amount of overhead.
> 
> If you are looking for a good set of classes that can handle generic 
> caching, I'd strongly recommend using the Zend_Cache system.
> http://www.framework.zend.com/manual/en/zend.cache.html
> 
> Zend cache will support disk-based caching and memcache or APC too all 
> via the same API.
> 
> Col
> 
> 
> 
> 
> 
> -- 
> 
> Colin Guthrie
> gmane(at)colin.guthr.ie
> http://colin.guthr.ie/
> 
> Day Job:
>    Tribalogic Limited [http://www.tribalogic.net/]
> Open Source:
>    Mandriva Linux Contributor [http://www.mandriva.com/]
>    PulseAudio Hacker [http://www.pulseaudio.org/]
>    Trac Hacker [http://trac.edgewall.org/]
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/PHP-XSLT-caching-tp20173225p20174548.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---
vladimirn wrote:
Thank you Col
I will go into Zend_Cache as you suggested.
One more thing- does Zend_Cache saces data into file or use a server memory?

As I said in my original mail, but perhaps wasn't clear, Zend_Cache can support file, memcache, APC and other backends.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
vladimirn wrote:

> i was wondering whats the best approach to do next.
> I have an xml file delivered from service of my partner. On my web
> server (windows) i have xslt files used for xml transformation.
> Those files are getting bigger, so i have request to cash them and use
> cashed. 

Your xslt files are source code, so why is there a need to cache them? 


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
Rob Gould schrieb:
Question about mySQL and PHP, when using the mySQL ORDER BY method...


Basically I've got data coming from the database where a "wine producer-name" is a word like:

    Château Bahans Haut-Brion

    or

    La Chapelle de La Mission Haut-Brion

    or

    Le Clarence de Haut-Brion

but I need to ORDER BY using a varient of the string:

1) If it begins with "Château", don't include "Chateau" in the string to order by. 2) If it begins with "La", don't order by "La", unless the first word is "Chateau", and then go ahead and order by "La".


Example sort: Notice how the producer as-in comes before the parenthesis, but the ORDER BY actually occurs after a re-ordering of the producer-string, using the above rules.

    Red: Château Bahans Haut-Brion (Bahans Haut-Brion, Château )
Red: La Chapelle de La Mission Haut-Brion (Chapelle de La Mission Haut-Brion, La )
    Red: Le Clarence de Haut-Brion (Clarence de Haut-Brion, Le )
    Red: Château Haut-Brion (Haut-Brion, Château )
    Red: Château La Mission Haut-Brion (La Mission Haut-Brion, Château )
Red: Domaine de La Passion Haut Brion (La Passion Haut Brion, Domaine de )
    Red: Château La Tour Haut-Brion (La Tour Haut-Brion, Château )
    Red: Château Larrivet-Haut-Brion (Larrivet-Haut-Brion, Château )
    Red: Château Les Carmes Haut-Brion (Les Carmes Haut-Brion, Château )


That logic between mySQL and PHP, I'm just not sure how to accomplish? I think it might involve a mySQL alias-technique but I could be wrong.

Right now, my PHP call to generate the search is this:

$query = 'SELECT * FROM wine WHERE MATCH(producer, varietal, appellation, designation, region, vineyard, subregion, country, vintage) AGAINST ( "' . $searchstring . '") ORDER BY producer LIMIT 0,100';


Hi,
Try to solve your Logic on your programming language and to select Data with your Database... Try to normalize more your Information on the Database.

Regars

Carlos

--- End Message ---
--- Begin Message ---
Ronald Wiplinger (Lists) wrote:
I need to clear a table (cache) from a database based on the database size.

Our web site uses cached pages. Our webhost only allow us 100 MB
storage. Usually the database is just 10 MB, but when a search engine
crawls our calendar, then the storage is quickly 108 MB. The system
reports then mathematically correct: Space left on database -8MB !!!

I plan therefore a web page, which is triggered by cron every hour and
will just clear the table.

Can I use just:
mysql_query("DELETE FROM cash")
or die(mysql_error());

If you really want to delete all rows, use

truncate cash;

otherwise the db deletes the entries row by row - which will be slow, and also it has to update all indexes on the tables as it is doing it.

--
Postgresql & php tutorials
http://www.designmagick.com/


--- End Message ---

Reply via email to