Re: [PHP] How define if javascript is on with php
On 16 April 2010 14:06, Paulo-WORK wrote: > On 16/04/2010 12:54, Ashley Sheridan wrote: > >> On Fri, 2010-04-16 at 12:50 +0100, Paulo-WORK wrote: >> >>> Hello and thanks for any replies that this message may get. >>> I have a issue to solve regarding PHP. >>> My website relies heavlly on jquery and does not dowgrade properly. >>> I use codeigniter framework as this website has a backend . >>> Is it possible to detect if js is on with php? >>> And if so can it be set into a variable? >>> Paulo Carvalho >>> >>> >>> >> >> Nope, Javascript is on the client side and PHP is on the server. The >> server has very little knowledge of the client, and what information is sent >> (browser type, etc) can't be relied upon because browsers are capable of >> lying about what they are (in order to make themselves appear as IE for >> example) >> >> JQuery should allow the site to fail gracefully into a non-Javascript >> version, because of the way the framework is built. >> >> If this is something that you cannot easily do, why don't you just have >> PHP output some sort of default message that the site does not work without >> Javascript and use CSS to hide the rest of the site that requires script. >> Then, in JQuery, it's simple to hide the message and show the site with a >> couple of lines of code. >> >> However, I would recommend trying to get your site to fail gracefully if >> it's possible, especially if it's going to be used by the public. Many >> countries (including Australia, US and most of Europe) have laws regarding >> accessibility now, and while the number of actual legal cases is extremely >> minor, it's not a good thing to ignore. Not only that, but even looking at >> the web stats offered by the W3C it shows that about 5% have Javascript >> turned off. Think about the entire world population that represents and >> suddenly 5% isn't such a small figure after all! >> >> Thanks, >> Ash >> http://www.ashleysheridan.co.uk >> >> >> Thanks for your replies. > I have at this stage a redirect stating that this website requires js to > work. > the website is http://paulocarvalhodesign.co.uk > I am a selfthaught wannabe developer and my goal to this private project is > to create a aplication very similar to flash. > This website does not refresh until you actually hit refresh button on > browser. > if i remove the redirect the pages will be all over the place. > please see it for yourselfs > sorry if my sppelling is not the best. > Paulo Carvalho > The nicest way, in my opinion, is to simply display the alternative content for the site and override it if Javascript is present. If it's turned off, people will see your static content, and if it's on they'll get the full experience. Having alternative content is important because it allows Google to properly index your site. Finding a way to check if Javascript is turned on while still in server side is really unnecessary, since displaying alternative content and removing or hiding it client side works just as well as redirecting to an alternative page. Michiel
Re: [PHP] How define if javascript is on with php
On 16 April 2010 19:02, tedd wrote: > At 3:46 PM +0200 4/16/10, Michiel Sikma wrote: > >> On 16 April 2010 14:06, Paulo-WORK wrote: >> >> -snip- >> > > Paulo: > > I agree. Here's a working example with everything you need: > > http://sperling.com/examples/javascript-detection/ > > Cheers, > > tedd > > Another important thing to consider is that the web is meant to be accessible to even those using a screen reader. Screen readers don't support Javascript (to my knowledge) and instead rely on properly written HTML. By having regular content and overriding it with Javascript, you're ensuring that the visually impaired, among others, can also use your site. Michiel
Re: [PHP] PHP include security
On 16 April 2010 06:57, Micky Hulse wrote: > Hi, > > -snip- > > The above code snippet is used in a class which would allow developers > (of a specific CMS) to include files without having to put php include > tags on the template view. > > The include path will be using the server root path, and the include > files will probably be stored above the web root. > > My question: > > What would be the best way to "clean" and secure the include string? > > Maybe something along these lines (untested): > > $invalidChars=array(".","\\","\"",";"); // things to remove. > $include_file = strtok($include_file,'?'); // No need for query string. > $include_file=str_replace($invalidChars,"",$include_file); > > What about checking to make sure the include path is root relative, > vs. http://...? > > What do ya'll think? Any suggestions? > > Many thanks in advance! > > Cheers, > Micky > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Hi, It depends. What's exactly do you want to prevent? It doesn't seem like a very big problem if someone tries to include an improper adderss or nonexistent file, since that would simply make $data an empty string (depending on your level of error reporting and whether you display or hide warnings). If the included file decides to call ob_get_clean() or something like that $data will be false. I can't think of what else you realistically want to prevent. Building a page with multiple templates is best done by using a good template class. Allowing the inclusion of external PHP files from a CMS will pose a risk if non-developers have access to the CMS as well. You're basically allowing anyone to add (potentially untested) code to a live site and I would recommend against doing it. If you want people to be able to include, say, additional HTML content, use file_get_contents() instead. Michiel
Re: [PHP] limit to var_dump?
On 16 April 2010 16:15, Ashley Sheridan wrote: > I'm seeing some strange behaviour with var_dump. Is there a limit to how > many levels deep that var_dump can display? > > -snip- > > However, when I var_dump the top-most object (the Gantt object) the > predecessors array for Gantt_Task 1.2 just shows as '...'. If I var_dump > that particular object, I can see that the correct array element does > exist. > > Is this just a random bug I've found, or is there an intended limit to > how complex and deep var_dump can go? Would it have anything to do with > the fact that Gantt contains multiple instances of the Gantt_Task > object? > > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > There's a limit to var_dump if you have Xdebug installed. See the Xdebug site: http://www.xdebug.org/docs/display On another note, iirc var_dump itself can detect and prevent infinite recursion. Michiel
Re: [PHP] Replacing a special character
On 18 April 2010 16:46, Peter Lind wrote: > On 18 April 2010 16:40, Phpster wrote: > > > > > > On Apr 18, 2010, at 8:59 AM, Michael Stroh wrote: > > > >> I have this form that people use to add entries into a MySQL database. > >> Recently I've had some users insert − in their entries instead of - > which is > >> causing some issues with scripts down the line. I'd like to replace the > − > >> character with -. > >> > >> Originally I had something like > >> > >> $name = mysql_escape_string($_POST["name"]); > >> > >> which would convert the offending character to − before entering > it > >> into the database. It's this encoding that is causing the problems since > >> some scripts send out emails with this entry in their subject line which > >> looks messy. > >> > >> I've tried adding the following line after the previous line to help fix > >> this issue, however, I just got another entry with the same problem. > >> > >> preg_replace('/−/','-',$name); > >> > >> Any suggestions on how others would fix this problem? I'd just like to > fix > >> it before the entry hits the database instead of creating fixes on the > other > >> end of things. > >> > >> > >> Cheers, > >> Michael > >> -- > >> PHP General Mailing List (http://www.php.net/) > >> To unsubscribe, visit: http://www.php.net/unsub.php > >> > > > > One option is to send an HTML email which would have the email reader > > interpret that code correctly > > > > Bastien > > Another option would be to use mysql_real_escape_string and make sure > that your code and the database are using utf-8. Then when the email > is sent, make sure that uses utf-8 as well. > > Regards > Peter > > Make sure the database connection is also utf8: set names 'utf8'; Typically, you should keep everything in utf8 unless you have a very good reason not to. And as Peter mentioned, the proper way to escape MySQL inserts (that is, if you're not already using a framework that does this competently) is mysql_real_escape_string(). Michiel
Re: [PHP] PHP include security
On 18 April 2010 02:08, Micky Hulse wrote: > Hi Michiel! Thanks for the help, I really appreciate it. :) > > > It depends. What's exactly do you want to prevent? It doesn't seem like a > > .. > > include, say, additional HTML content, use file_get_contents() instead. > > Very good points. My goal was to write a plugin that would allow me to > include some static HTML template file and get the > tags out of my CMS template. With that said, I think the only people > using this code will be the developers of the templates, and not your > standard user. > > I opted to use output buffering and readfile() for the speed, and > include() would be an option if developers want to execute the code in > the included file. > > Would file_get_contents() be faster than readfile and output > buffering? Would using file_get_conents() and eval() be faster than > using include() and output buffering? > I would prefer to use include() since it runs the code in the same context, and using both file_get_contents() and eval() is a bit of a detour. eval() also tends to be a lot slower than included code (though I'm not exactly sure how slow). I'm also not entirely sure whether file_get_contents() is slower than readfile(), but file_get_contents() is useful if you want to do something with your data rather than printing it right away. Michiel
Re: [PHP] solution
On 17 April 2010 13:03, Paulo-WORK wrote: > I have reached a solution for my problem with js. > Following all the sugestions and using jquery turned out to be quite > simple. > using .hide( ) and .show( ) i am able to change the #div with Js enabled > content and no js. > > That's the best way to go. After all, the only real way to detect Javascript is to *use* Javascript :) Michiel
Re: [PHP] How to do i18n better?
On 19 April 2010 00:55, Andre Polykanine wrote: > > Now the i18n process is made as follows: we set a cookie on the site > and depending on it we select the language to display the site in. We > have three (currently) interface files: rus.lng, ukr.lng, and enu.lng > (for English US). the format is the following: > define ("MSG379", "Welcome!"); > > You might want to consider making the language dependent on the URL, e.g. http://site.com/ru/pagename for Russian. Doing it this way certainly isn't a bad solution, but I do strongly recommend against using define() and using anonymous translation keys. Usually, you have one base language (which is usually English due to its lack of special characters and ubiquity) from which you work. You then either simplify your keys, e.g. 'user_welcome' => 'Welcome, %1$s!', or make the keys the proper base language strings so you can wrap everything in a language function. In the latter case, you might have something like , and then if the current language is not English, the _() function will make the appropriate lookup. The advantage of this is you won't need to have a tertiary source to tell you which MSG### corresponds to which piece of text. Michiel
Re: [PHP] PHP include security
On 18 April 2010 21:43, Micky Hulse wrote: > On Sun, Apr 18, 2010 at 10:23 AM, Michiel Sikma > wrote: > > I would prefer to use include() since it runs the code in the same > context, > > .. > > with your data rather than printing it right away. > > Thanks for the reply Michiel, I really appreciate it. :) > > For some benchmarks on the different types of inclusion > functions/language constructs, this page has some good info: > > <http://www.raditha.com/wiki/Readfile_vs_include> > > The results are interesting. > > One thing to keep in mind is that this one doesn't take eval() vs regular include execution time into account, in case you were still considering using it. According to this page, it's many times slower: http://blog.joshuaeichorn.com/archives/2005/08/01/using-eval-in-php/ Michiel
Re: [PHP] How to do i18n better?
On 19 April 2010 15:56, Robert Cummings wrote: > -snip- > > > Unless you have namespaces (and I can't remember if they completed > namespaced based functions) then don't use something so commuon as a > function named underscore :/ > > Cheers, > Rob. > > No, you're actually absolutely right about that, since I had a custom function in mind when I wrote that example code, not PHP's built in gettext function ;) I use frameworks so I end up doing $this->lang() or something similar myself. Michiel
Re: [PHP] replying to list
On 21 April 2010 11:23, David McGlone wrote: > > Why is the list set up to reply to the OP and not the list? > > -- > Blessings, > David M. > > Is it? I didn't notice. I just use "reply to all" which puts the list in the CC, and that works just fine for me. Michiel
Re: [PHP] Date Math
On 20 April 2010 17:40, Floyd Resler wrote: > I need to get the difference in months between two dates. The dates could > be as much as 60 months apart. Is there any easy way to do this either > through PHP or MySQL? I know how I can do it through code but thought there > might be a simple one or two line option. > > Thanks! > Floyd > > You're best off doing this in MySQL. Something like select timestampdiff(month, '2010-01-01', '2010-05-22'); should work. Michiel
Re: [PHP] replying to list (I give up)
On 21 April 2010 15:41, Dan Joseph wrote: > When you hit reply all, just take out all the other addresses and leave the > list one in there. The list was setup like this years ago on purpose, and > they've stated in the past they don't want to change it.. > > -- > -Dan Joseph > > I'd like to refrain from actually passing judgement on this issue--since I use reply-all by default I could live with both of these settings--but I'm still curious as to why the list is set up the way it is. What is the advantage of sending to the OP by default rather than the list? Michiel
Re: [PHP] Hello everybody - php newbie from switzerland
On 21 April 2010 18:02, tedd wrote: > > Welcome Nick. > > Do you own a bank? :-) > > > Cheers, > > tedd > > C'mon, this is the PHP list, not COBOL :) But yes, welcome to the list. Frequenting a list is one of the best things you can do when learning a language. Don't be afraid to ask should anything confuse you. Michiel
Re: [PHP] collect string from string
You need to use the multiline modifier. Try this: preg_match_all("/^(\#.*)/im", $my_string, $matches); print_r($matches); The result: Array ( [0] => Array ( [0] => # {{uncountable}} The dried leaves or buds of the [[tea plant]], [1] => #: ''Go to the supermarket and buy some '''tea'''.'' [2] => # {{uncountable}} The drink made by [[infuse|infusing]] these dried ) [1] => Array ( [0] => # {{uncountable}} The dried leaves or buds of the [[tea plant]], [1] => #: ''Go to the supermarket and buy some '''tea'''.'' [2] => # {{uncountable}} The drink made by [[infuse|infusing]] these dried ) ) Michiel On 22 April 2010 22:38, saeed ahmed wrote: > this is not working > > /^(\#.+)$/g > > I have tried the preg_match function > > - > Regards > Saeed Ahmed > http://saeed05.wordpress.com > - > > > On Thu, Apr 22, 2010 at 11:39 PM, Ashley Sheridan > wrote: > > > On Thu, 2010-04-22 at 23:41 +0600, saeed ahmed wrote: > > > > hello friend, > > > > I have a string like below > > " > > > > ===Pronunciation=== > > * {{enPR|tē}}, {{IPA|/tiː/}}, {{SAMPA|/ti:/}} > > * {{audio|en-us-tea.ogg|Audio (US)}} > > * {{audio|En-uk-tea.ogg|Audio (UK)}} > > *: {{rhymes|iː}} > > * {{homophones|T|te|tee|ti}} > > > > > > # {{uncountable}} The dried leaves or buds of the [[tea plant]], > > ''[[w:Camellia sinensis|Camellia sinensis]]''. > > #: ''Go to the supermarket and buy some '''tea'''.'' > > # {{uncountable}} The drink made by [[infuse|infusing]] these dried > > leaves or buds in hot water. > > Usage notes > > In the [[United Kingdom]], [[Canada]], other English speaking > > [[Commonwealth]] countries, and in northern areas of the [[United > > States]], ''tea'' is assumed to mean [[hot]] tea and is usually served > > in a [[teapot]] with separate [[cup]]s, or sometimes served directly > > in cups such as for large groups or for [[takeout]]. > > > > In southern areas of the United States, ''tea'' is assumed to mean > > [[iced tea]] and is usually served with ice, either in a [[pitcher]] > > with separate [[glass]]es or directly in glasses. > > > > Strictly speaking, "tea" has been reserved for [[infusion]]s made from > > leaves of ''[[w:Camellia sinensis|Camellia sinensis]]''. Infusions > > made from other [[herb]]s such as [[rooibos]], [[mint]]{{,}} and > > [[chamomile]] are called [[tisane]]s. In recent years the word "tea" > > has been extended to include the herbal infusions. > > > > Synonyms > > * {{italbrac-colon|dried leaves of tea plant}} [[tea leaves]] > > * {{italbrac-colon|drink made by infusing parts of various other > > plants}} [[herb tea]], [[herbal tea]], [[infusion]], [[tisane]] > > > > Derived terms > > > > " > > > > now I want to collect only the string which are start with '#'. how > > can I do this? please suggest me. > > > > > > - > > Regards > > Saeed Ahmedhttp://saeed05.wordpress.com > > - > > > > > > If the text is in a file, use file() to read the contents into an array > and > > then check the first character. > > > > Alternatively, if the text is in a string, you could use a regex to pull > > out only matching lines. This is an untested regex, but it should do the > > trick: > > > > /^(\#.+)$/g > > > > Thanks, > > Ash > > http://www.ashleysheridan.co.uk > > > > > > >
Re: [PHP] collect string from string
On 23 April 2010 00:42, Ashley Sheridan wrote: > On Fri, 2010-04-23 at 00:44 +0200, Michiel Sikma wrote: > -snip- > Ah, ignore my last reply then! I used the g modifier, forgetting it wasn't > the multi-line one in PHP! > > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > It's the global modifier in other implementations (JS, Perl, Java, etc), but it doesn't quite work like the multiline modifier in those implementations either. The effect of having it is like the difference between PHP's preg_match() and preg_match_all(). That's why PHP actually doesn't have a g modifier. Michiel
Re: [PHP] Structured PHP studying
On 23 April 2010 13:15, David McGlone wrote: > Is there a good strategy to studying PHP? > > For instance, is there a way to break everything down into small managable > topics? > > -- > Blessings, > David M. > > Just build what you want to build and look things up when necessary. The biggest part of learning any language is becoming able to creatively solve problems within its realm of possibilities, and that's something you can't really learn just by reading and solving textbook problems. Hands-on experience is a very important key to understanding. Keep an open mind, ask people for answers if things get difficult, always assume that there's a better way to do something, and in a while you'll be able to write perfectly decent programs. Michiel
Re: [PHP] Question: Farsi characters showing as jibberish
On 24 April 2010 14:45, Parham Doustdar wrote: > Hi, > > I have created a PHP file, and wrote a string of Farsi letters in it. In > the > head section of the HTML, I put: > > > > There appears to be something wrong with Apache, or something, because no > matter whether I put that string in an echo statement or just in an HTML > with a php extention, the page loads as jibberish and I have to set the > character encoding to UTF-8 manually in Firefox. > > Renaming that same file to .htm (when not using the echo statement), and > loading it in the browser shows me the correct Farsi characters. > > Should I change something in Apache's settings for this to work? > > Thanks! > > > No, that should work perfectly fine. Are you sure that the PHP file itself is utf-8? Could it be that you manually set the text encoding to something else in your browser, causing it to remember that setting? Perhaps you could link us to the page itself so we can have a look. Note that the best place to put that tag is right after the opening tag, before any other header information. Michiel
Re: [PHP] Re: replying to list (I give up)
On 23 April 2010 16:16, Kevin Kinsey wrote: > > I've still got a Win98 box in service somewhere around here; I use > it for audio recording. Someone (possibly even me) renamed most > of the desktop icons ... OE's shortcut is "Outluck Depress". :-) > > Kevin D. Kinsey > > Say what you will about Windows 9x systems, but they (and especially Windows 95) ran rather well on just 60 MHz. Sure, computers are constantly getting faster, but fortunately software developers keep coming up with new ways to make us wait. :) Michiel
Re: [PHP] htmlentitites ENT_QUOTES in HTML attributes?
On 23 April 2010 14:21, Jan G.B. wrote: > Hi List, > > I just figured, that the Browsers on my system do interpret ' > inside href or onclick attribute as a plain '. > > Imagine the user input is the following line: > > param2" foo';);alert(document.cookie);alert(' > > Which is being written by the script like that: > > test > > USER_INPUT is sent through htmlentities($str, ENT_QUOTES, 'UTF-8'); > > The result is the following then: > > > > function example(a, b) { > alert('valid alert; params: '+ a+', '+b); > } > > > test > > > > My browsers will alert the document.cookie. > Please confirm this (and keep in mind that document.cookie is just > empty when tested locally). > > > Regards > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Yes, ' is the same as a single quote. But let's say you set up your page like this: http://pastie.org/932923 Submitting the form will change the $input variable that's also added to the Javascript below. So in theory, you should be able to submit, say, '+window.very_important_variable+' in order to get an alert with the secret number 255 in it. But when submitting that text in the form, the & actually gets converted to &, causing the alert() to literally print the string '. When submitting a real single quote, it gets converted to \', printing a literal '. The only way to get to the window.very_important_variable is by removing the htmlentities() function in the PHP code. The test case you added is incorrect, since properly sanitized input would never have an actual, non-escaped ' in it. Michiel
Re: [PHP] Re: replying to list (I give up)
On 24 April 2010 16:14, Per Jessen wrote: > Ashley Sheridan wrote: > > >> > >> Is there an actual WoW client for Linux or you run in Wine like > >> environment? > >> > >> Thanks, > >> Tommy > >> > > > > I run it under Wine. Wine has come a long way since my first > > encounters with it a few years back and run a surprising amount of > > Windows-based software. > > Doesn't WoW need DirectX and all that? I have some old Windows games > (Diablo, Alpha Centauri, Railroad Tycoon, Wolfenstein) I'd love to play > under Wine, but so far I've not managed to make them work. > > The best way to run old games is via DOSBox. http://www.dosbox.com/ If you have an Intel machine it should run pretty well (at least the latest version will; some repos still have the old 0.65 version which is significantly slower). Michiel
Re: [PHP] Question: Farsi characters showing as jibberish
On 24 April 2010 16:07, Parham Doustdar wrote: > Hi Ashley and Michiel, > > It appears it is something in Apache or my server program on Windows (I am > using Uniform Server; a portable webserver from > http://www.uniformserver.com). The reason I got to such a conclusion is > this: > > 1. I uploaded the pHP file to a free hosting website. Here is the URL: > http://blindmoviebuff.uphero.com/test2.php > > 2. I put the same page in my www folder in Windows. Here's the address to > that: > http://parham-d.dyndns.org/test2.php > > As you can see, the page on uphero.com displays without any encoding > changes > required by you, whereas the second has to be manual (for some reason). -snip- > > Actually, both of these work fine for me. I don't have to manually set the encoding to get the Farsi characters to show up in either of these links. I don't know why it wouldn't work for you. Maybe you should try a different browser to make sure it isn't a cached setting. Adding the header() call that Ashley suggested also seems like a good idea. Michiel
Re: [PHP] PHP not being read?
On 25 April 2010 00:45, Gary wrote: > What would cause a machine not to read/process php? > > I have a laptop that I have been ever increasing using for php scripting. > I decided to do a simple experiment, it started out something like: > > $seconds=1; > $minutes=$seconds*60; > $hours=$minutes*60; > $days="$hours*24; > > echo $seconds; > echo $minutes; > echo $hours; > echo $days; -snip- > > A text editor with syntax highlighting would certainly help. There's a double quote " right in front of the $hours variable on the fourth line. That's an unterminated string literal, a syntax error, which would cause PHP to abort entirely. Your php's error log probably has a message in it to this extent. The reason why you got a number of different results is probably because you added another double quote further down in later versions. But if that's somehow not it, post the entire source code of your file on a site like http://pastie.org/ so we can have a closer look. Michiel
Re: [PHP] Re: replying to list (I give up)
On 25 April 2010 09:31, Per Jessen wrote: > > >> Doesn't WoW need DirectX and all that? I have some old Windows games > >> (Diablo, Alpha Centauri, Railroad Tycoon, Wolfenstein) I'd love to > >> play under Wine, but so far I've not managed to make them work. > >> > >> > > The best way to run old games is via DOSBox. http://www.dosbox.com/ > > Yes, I do use that too, but will it also run Windows games?? > > > Ah, you're right, I misread. But I believe all of those games except Diablo will run under DOS as well. DOSBox can also run up to Windows 3.11. Michiel
Re: [PHP] Error handling strategies (db related)
On 27 April 2010 10:42, Gary . wrote: > How do you guys handle errors during, say, db insertions. > > Let's say you have an ongoing transaction which fails on the n-th > insert. Ok, you roll back the transaction, no problem. How do you then > inform the user? Just using the text from pg_result_error or > something? > > Developers are usually lazy about error reporting because it's much easier to just return the error code. Some parsing is very useful to the user, since overtly technical information is just confusing. The error should never be something that the user himself can avoid (since you're supposed to have error checking and handling before the user submits), so your error should make this clear to him. It helps to let him know that the developer has been notified and that he can try again later. Michiel
Re: [PHP] Inconsistent json_decode() results
2010/5/5 Ali Asghar Toraby Parizy > 2010/5/5 François Beausoleil : > > Hello all! > > > > We're seeing inconsistent json decoding between PHP versions: > http://gist.github.com/390090 > > > > Calling json_decode() from 5.2.6 returns an associative array when asked, > while 5.2.10 always returns a stdClass. Is this a bug or a problem with my > calling convention? > > > > Thanks! > > François > > I think this is a bug, since you're using it correctly. 5.2.11 seems to have fixed the problem: http://pastie.org/947103 Michiel ps to Ali, most people here seem to prefer it if you type your reply at the bottom of the previous post. I personally don't mind since my client (Gmail) hides quoted text by default, but it does make things easier if you can see the quoted text.
Re: [PHP] Inconsistent json_decode() results
2010/5/5 François Beausoleil > Hello all! > > We're seeing inconsistent json decoding between PHP versions: > http://gist.github.com/390090 > > Calling json_decode() from 5.2.6 returns an associative array when asked, > while 5.2.10 always returns a stdClass. Is this a bug or a problem with my > calling convention? > > Thanks! > François By the way, if you're stuck on 5.2.10, you could simply cast the result to array: var_dump((array)json_decode('{"_urls": ["a", "b"]}')); Michiel
Re: [PHP] Two color rows in table inside while iteration -- just say no to mod
On 3 May 2010 08:25, Jochen Schultz wrote: > > [snip] > > And unless we are adding a multiple seconds to the load time is anyone >> going to notice a difference of 1 second? >> > > yes > > > It's really not that big a deal. http://pastie.org/947121 Personally, I think using modulus is as nice a solution as flipping a bit. Maybe more elegant since it's extendable to more than 2 states if required. Michiel
Re: [PHP] Inconsistent json_decode() results
On 5 May 2010 20:02, Michael Shadle wrote: > 2010/5/5 Michiel Sikma : > > > By the way, if you're stuck on 5.2.10, you could simply cast the result > to > > array: > > > > var_dump((array)json_decode('{"_urls": ["a", "b"]}')); > > I don't see a "available starting in 5.x.x" notice, so I think it's > been there for a long time... > > http://www.php.net/json_decode > You're right, but this is about how 5.2.10 ignores the second parameter and always returns a class, which appears to be a bug. I'm not sure which other versions have this same problem, but 5.2.11 has correct behavior, which seems to suggest they found and fixed it by then. I can't find an entry for this problem in PHP's bug database, however. My suggestion to typecast the result of json_decode() should only be followed if you need an array and are required to work with version 5.2.10. Michiel
Re: [PHP] Inconsistent json_decode() results
On 5 May 2010 22:14, Michael Shadle wrote: > -snip- > > A. I gotcha now. Yeah I started using that just recently either > 5.2.11 or 5.2.13 (not sure which) > > You can typecast an object to an array that easily? I was unaware. > Yep, it's that easy. :-) // array(1) { // [0]=> // int(1) // } var_dump((array)1); // array(1) { // [0]=> // string(1) "a" // } var_dump((array)'a'); // array(1) { // ["c"]=> // string(1) "d" // } class b { public $c = 'd'; } var_dump((array)new b()); Michiel
Re: [PHP] In need of CVS/SVN checkout script for Production servers [solved]
On 5 May 2010 17:18, tedd wrote: > At 1:10 PM -0700 5/4/10, Daevid Vincent wrote: > >> Well, here is the one I'm using. I ended up just writing one (again!) >> >> http://www.daevid.com/content/examples/snippets.php :: "Production >> Deployment Script" >> > > What?!? > > Advanced features?? > -snip- > Just want to add my +1 to this. I'm running Safari, which most definitely will support whatever advanced features you put in there, and I'm being blocked. Putting aside the level of standards compliance of your site, you really should blacklist browsers instead of whitelisting them. Sites should never become inaccessible if your browser lacks features, and even if the entire site revolves around some fancy Javascript, you should at least provide a "go ahead at your own risk" link in case you're accidentally shutting out the wrong browser. Here's an example from a site I made a while ago which mimics the workings of Gmail. It's accessible to screen readers through alternative content, and if you're trying to visit using IE6 (we consciously decided not to apply browser fixes for it), you get the following message: http://wedemandhtml.com/tmp/tag_ie6_is_unsupported.png Michiel
Re: [PHP] Two color rows in table inside while iteration [X-PHP]
On 2 May 2010 19:11, tedd wrote: > > > > -snip- > Yes, it would be nice if the people who work for the government also had to > live under the same rules as the rest of us. As it is, they live in a state > of privilege enjoying salaries that are typically 175 percent above that of > the private sector with benefits to match. They do this without advancing > the quality of life for anyone -- they have no purpose other than to push > papers, collect *their* wages, enjoy *their* health insurance, and wait for > *their* lavish retirement. Of course, they claim they have purpose, but most > of us know better. The sooner we reduce the size and importance of > government, the better off we all will be. > > > > Cheers, > > tedd > > Hello, I'm not a moderator of this list, but I would like to ask you to please not use the PHP list for such confronting political diatribes. This is a very well known talking point that can easily elicit a lengthy off-topic discussion, and I don't think anybody is really interested in that. Again, this is just my opinion, but while it's okay to talk about things other than PHP on occasion, I don't really see what use this has other than provoking a response from someone. Please be considerate is all I'm asking. Michiel
Re: [PHP] Really impressive work
On 6 May 2010 00:04, tedd wrote: > Hi gang: > > I found something that really impressed me -- please review this: -snip- > Now, we also have smaller images of 12 different stones (in heads) that are > all the same size. Thus, as the user picks the stones and positions they > want and the image is assembled "on the fly". > > Is that the way you see this? Or is there a better way? > > Cheers, > > tedd > > Personally, I wouldn't bother building an image generator (which isn't that difficult to do with GD or Imagick--and I wouldn't go as far as to save the values in a database). This can easily be done in Javascript. The only reason to build an image generator is if the images need to be used in a non-browser environment, e.g. sent to the user in an e-mail or enclosed in a PDF. At minimum you need all colorized images of the jewels, but you could even do with one single image and colorize it using . Too bad that's not supported in anything other than (iirc) Firefox and the Webkit nightly. Michiel
Re: [PHP] Getting source from remote file
On 6 May 2010 10:55, Peter Lind wrote: > > > You could parse the document with the DOM classes. Load as a > DOMDocument, then grab what's needed with the relevant methods (you > can use xpath to single out your divs with the right classes). > http://dk2.php.net/domdocument > > > Xpath is indeed the way to go. For example... /* .. your code.. */ $data = file_get_contents($url); $inDoc = new DOMDocument();$inDoc->preserveWhiteSpace = false;@$inDoc->loadHTML($data); $xpath = new DOMXPath($inDoc);$xlinks = $xpath->query('//d...@class="b"]/a');for ($a = 0, $z = $xlinks->length; $a < $z; ++$a) { $link = $xlinks->item($a); $href = $xlink->attributes->getNamedItem('href')->value; } To be safe, you should use an ID instead of a class, though. Michiel
Re: [PHP] Two color rows in table inside while iteration [X-PHP]
On 6 May 2010 17:47, tedd wrote: > > > Michiel: > > Considerate? Being Inconsiderate is what the government does for a living. > > Additionally, what you said above is *your* opinion -- as *you* presented > in a public forum. Who's opinion is more appropriate for this list is > subject to debate. > > As for me, I'll say whatever I want as the topic permits. If you will > review this thread you will see that I was offering my code free to everyone > except government. That's not an opinion but rather a statement of > requirement for the code I'm providing. My second post to this thread > contained the reason WHY the requirement. > > If you don't like my requirements, and reasons for them, then please > forward my postings to the trash and don't use my code. > > > Cheers, > > tedd > > It appears as though I struck a wrong chord. I honestly did not mean to upset you. :) My point was that we should not be overtly confrontational towards one another, but it seems that only exacerbated the situation. My sincerest apologies. Regards, Michiel
Re: [PHP] mysql_real_escape_string() and "
On 14 May 2010 22:03, Spud. Ivan. wrote: > > I'm trying to insert a serialized data into mysql, but I does > mysql_real_escape_string() before inserting it. > > INSERT IGNORE INTO `table` (`value`) VALUES > ('a:3:{s:12:"F1";s:6:"nombre";s:11:"F2";s:5:"F3";s:16:"F4";s:10:"F5";}'); > > it result in > INSERT IGNORE INTO `table` (`value`) VALUES > (\'a:3:{s:12:\"F1\";s:6:\"nombre\";s:11:\"F2\";s:5:\"F3\";s:16:\"F4\";s:10:\"F5\";}\'); > > and of course it's not a valid SQL sentence. > > Why can't I escape an SQL value with " ??? > > Regards. > > I.Lopez. > > Hello, Actually, the problem is that you're not just escaping the content of the insert, but the entire insert statement itself. You need to only escape the data, not the query. To properly prepare your statement, you need something like this: $sql = "INSERT IGNORE INTO `table` (`value`) VALUES ('".mysql_real_escape_query($my_serialized_string)."');"; Note that the mysql_real_escape_string() function is *not* affecting the apostrophes (') that delineate the value. Michiel
Re: [PHP] opening a link in a new window
On 14 May 2010 22:49, Ashley Sheridan wrote: > > There are still valid reasons to use it. On my own site for example, and > links which lead outside of my site open up in a new tab/window. I link > to a lot of other external sites often in my blog entries, and I think > it's valid that these links open up in new tabs/windows so that my site > is left open when they read the rest of the article. > > I guess I could add some form of indication that the link will open up > in a new window though. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > I don't entirely agree that the target attribute should be avoided, or that you absolutely need to use Strict XHTML rather than Transitional. There really aren't that many differences between them. Yes, a lot of legacy elements were removed, but those that program in valid XHTML tend to not use them anyway. The real reason why target is a little ill-conceived is because not all target devices are able to use it in a valid way, e.g. phones with simple web browsers. But if it was never your intention to support those devices, using Transitional and the target attribute really isn't an issue. Michiel
Re: [PHP] MVC logic
On 29 May 2010 20:39, Tanel Tammik wrote: > Hello, > > i'm trying to break this thing down for my self. i made little application > for that. could someone please take a look and let me know if what i wrote > resembles MVC inviroment or not. > > It's crucial that your application parses the location (e.g. http://site.com/my/url-title/) and then loads a controller. As it is right now, your index.php is hardcoded to load the "messages" controller. That shouldn't happen. You should refactor your application so that the index.php does nothing except load the config, parse the request and then load the appropriate controller. And you should move the "templates" directory to the "application" directory (and maybe call it views for clarity). Everything that the user writes should be in one directory so that he can update the underlying system without deleting or overwriting files that he made. Regards, Michiel
Re: [PHP] Generic Email
On 9 June 2010 11:59, Richard Quadling wrote: > On 9 June 2010 09:08, Amit Bobade wrote: > > Hi friends, > > I am new in PHP. I want to know that how to send an email in HTML > > format(i.e. with proper header, footer, etc) in PHP. > > Please suggest me with code. > > > > -- > > Thanks and Regards, > > Amit > > Well, you can simply use PHP's built in mail() function, documented here: http://php.net/manual/en/function.mail.php It's extremely easy to use, particularly if you copy and change the code examples. If you want something more powerful, try Swift Mailer: http://swiftmailer.org/ Michiel