Re: [PHP] Why is this array_walk_recursive action not working? [SOLVED]
Feln, Richard, Jim, Thank you for responding. I understand now that the problem wasn't with variable scope, but with my lack of understanding of what array_walk_recursive returns. Thank you all for your explanations. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Why is this array_walk_recursive action not working?
PHP users, I obviously don't understand what array_walk_recursive does. Can someone break down in simple terms why the following doesn't work? - - - $karamohOutput['test'] = ; function test_print($item, $key) { return $key holds $item\n; } $karamohOutput['test'] .= array_walk_recursive($karamohArray, 'test_print'); - - - Any advice would be much appreciated. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why is this array_walk_recursive action not working?
FeIn, Thank you for responding. what did you expect to happen when you call array_walk_recursive? What I don't understand is why it did not append to the string as it walked through each key/value pair. It seems like even though the variable inside the function called by array_walk_recursive has the same name as a global variable, it gets treated as if it only has local scope and nothing done to it applies to the global variable. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Broken pipes, time outs, PHP, and mail
Peter, Bob, Thank you for replying. After a few days testing, I set up an error handler for when messages don't get sent. I started to see an error saying Language String failed to load, which seems to be particular to the PHPmailer scripts I am using. Long story short, after some searching on the web, it looks like the sending of mails will die if one mail on the list is invalid. I tried sending a message out to the list, got back a response saying that the recipient did not exist. So I deleted that user, and then the mail went through fine on the next attempt. I'm a little fuzzy on what exactly is happening. Does the PHP mail() command (and by extension, classes built upon it) listen for responses from the server it is sending to? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Broken pipes, time outs, PHP, and mail
Bob, Thank you for replying. Your code should be able to re-open the connection at this point and resend the message that triggered the error. Then resume working on the rest of your list. Unfortunately, it seems that this is not happening. The loop that sends out individual mail dies, and the remaining mails stop being sent. Is there perhaps some way I can force the PHP code to ignore the one mailing that failed and continue with the rest? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Broken pipes, time outs, PHP, and mail
Ash, Bob, Thank you for replying. There is one other possibility. According to the RFCs, the standard line ending for email is CRLF. Make sure your system is sending both characters after each line. There is a slim chance the server is cutting you off after some number of bytes if you are only sending a LF. This is actually a possiblity. I think I might be only using LF. Some of the text being sent in the emails is entered via a form on a web page. Is it possible to enforce CRLF on that text? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Malformed UTF-8 Data in JSON
PHP Users, I'm decoding some JSON data in PHP to convert it into an array. However, it's not working, and json_last_error() is returning a value of 4, which I believe means Malformed UTF-8 characters, possibly incorrectly encoded. I try at every turn in every setting to ensure that all my code and connections are in UTF-8. But how can I be sure it's valid UTF-8? I've tried using the PHP command utf8_encode() on the string, but that hasn't changed anything. And can I trust the error message? Any help or advice would be much appreciated. By the way, here is the code I'm currently testing with. I'm just encoding and then decoding a string right in the PHP just to get it to work before I even try getting the data from anywhere else. $myData ='{display_name:Test Guy,email:test...@testaddress.com,timeout:1279145273}'; $myArray1 = json_encode($myData); $myArray2 = utf8_encode (stripslashes($myArray1)); $myArray = json_decode($myArray2, true); $jsonerror = json_last_error(); -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Malformed UTF-8 Data in JSON [SOLVED]
Jim, Thank you for responding. Yes, stripslashes() was the problem. I've removed it and the code works. However, it seems that when I send JSON data from a Javascript file, stripslashes() is necessary. That's why I had it there. I'm not entirely sure what's going on there, so obviously more experimentation is needed. In any case, your suggestion has got me on the next step, so thanks for that tip. I'll add 2 cents to your tab! -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Anyone using Aptana and Xdebug? Or other debugger recommendations besides Zend?
PHP List, I won't go into a big rant about Zend, and instead simply say that while I was using Zend Studio to debug PHP pages since version 5.0. I was never really all that happy with it. It seemed to be the most complete debugging environment for PHP, so I put up with it. I will say that the Studio installation procedure has got better, but setting up a reliable debugging server has not. Now, the current version of Zend Studio (7.0) is based on Eclipse (I think since v6.0), and so I'm just not sure what I'm paying for anymore. Aptana Studio, also based on Eclipse has pretty much the exact same interface and can even connect to a Zend server. Since one of those is free, I can't see why I wouldn't switch. The issue for me is that paying for Zend hasn't really saved me much hassle, so even if Aptana has difficulties, at least they are free difficulties. The main failing point, so far as I can see, of Aptana/Xdebug, is a lack of good, clear, documentation (also note that Zend doesn't have great documentation either). Especially on how to set it up. I was wondering if anyone has used it and could provide a link or instructions on how to get the debugging environment up and running. Or, equally as valuable, would be recommendations on other debugging environments. The key is finding one that has a clear set of instructions for how to set it up (On Ubuntu/Debian Linux with a local LAMP server.) Thanks for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Die Page, Die! (Was: Preview button to show PDF without submitting post data?)
PHP List, Okay, so I've got a nice situation where a form has a preview button as well as a submit button. When the user presses Submit, the page reloads, and it emails a PDF. If the user presses Preview, it launches a new page in a new window, and also outputs a PDF directly to the user so they can review it. All good, but I don't need that second window open once the PDF has been shown to the user. For some reason I can't kill that second window. I've tried two methods. Killing it with PHP, and killing it with JavaScript. Here's the PHP version: if (isset($_POST['preview'])) { $pdf-Output(preview.pdf, D); die(PDF プレビュー出しました / PDF Preview Displayed); } Here's the JavaScript version: if (isset($_POST['preview'])) { $pdf-Output(preview.pdf, D); echo 'script type=text/javascriptjavascript:self.close();/script'; } But in either case, I keep getting that second page coming out, with the whole form rendered all over again. How can I kill a page? Once the PDF is rendered, I don't need it. I'd be okay if it came down to the browser then closed, but it would be better if the server sent the PDF and didn't send the page. Any advice would be much appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Die Page, Die! (Was: Preview button to show PDF without submitting post data?)
Ashley, Thank you for responding. I think you do, or where else would you show the PDF? Unless you force the PDF to download when the user clicks the preview button, you are left with the default option of the users browser, which will most usually be to display the PDF in the browser window. No, that's not what's happening. I'm not showing the PDF in a browser window. It's being given to the user with the option to download or view in a separate application. So I am fine with the download option. That's what I'm doing now, I suppose. So since the user is downloading the PDF, they don't need an in-browser window to view it. Once the PDF is downloaded/viewed, I want the new window to die by any means necessary. Surely there's a way. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Die Page, Die! (Was: Preview button to show PDF without submittingpost data?)
Nathan, Thank you for responding. yup.. forget the new window all together, if you have it set to download as an attachment then the user won't be taken away from the page; so no need for a new window at all. Right... so, we're all on board with the goals. Now... how do I do that? The whole problem here is that I keep getting a new window even though I don't want it. I would have thought if I told PHP to die immediately after outputting the PDF, it would give up on making the new window. I've also tried JavaScript to kill the window after it's made. *How* do I get the page to die? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Preview button to show PDF without submitting post data?
PHP Users, I have a page that generates a PDF document using PHP. It takes form data filled in by the user to fill out the PDF When the user clicks submit, it emails that PDF document to the intended recipient. However, I would like to add a preview function as well. But for a variety of reasons, instead of submitting the form data through post and re-filling all the fields with the selected data, I'd like to be able to open a new window with an example PDF without actually submitting the form. I think this might need JavaScript, but I'm not sure. Is this possible? Thank you for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Does anyone here use TCPDF?
Ralph, Paul, Thank you for responding. I don't use TCPDF; I use FPDF, but I imagine the drill is about the same I tried using FPDF, but it did not support UTF-8/Japanese. It claims some support in the documentation, but after much experimentation, I verified it does not. That is why I switched to TCPDF. What you're asking sounds like you want to *edit* an existing PDF via a PHP class, No, I just want to write on top of it. And that was possible with FPDI/FPDF, but I had to abandon those as they did not support Japanese. I attempted to use the same functions as FPDI/FPDF, but they did not work in TCPDF. have a look in the archive of this list. there is a topic writing japanese test in an excisting pdf its of 31. of August, this should help That was a thread I started. Things have changed slightly since I now know that only TCPDF supports Japanese. So I still need to know if/how to write text into a PDF, like I did with FPDF, but with TCPDF instead. If this turns out to not be possible, I am going to be suffering a great deal. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Does anyone here use TCPDF?
PHP List, I posted this question on the TCPDF forum on SourceForge, but it's getting no response. I'm not even sure how active their list is. http://sourceforge.net/projects/tcpdf/forums/forum/435311/topic/3400663 So I'm hoping someone here might be able to help if they are using TCPDF. I just need to get the key details to get started, and then I can probably start to roll on my own. This is the question: Forgive me for what I would assume is a very obvious question, but I can not locate any clear instructions on what I want to do. Simply, I want to take an existing PDF and write text on top of it. The PDF is a single page, and it is a form that people fill out. What I need to do is fill out some of the fields in the form before sending it to the recipient. So I need to do two simple tasks. One is to load an existing PDF file. The second is to place short lines of text into specific locations on the page (A4 size). I know these two functions must be dead simple, and yet I am lost in the documentation. If someone could tell me the right function calls or point me to the right place so that I can RTFM on my own, I would be very grateful. Thank you for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Write Japanese text into an existing PDF [SOLVED]
Tedd, Thank you for responding. I used the PDFB library to create this: http://chir.ag/projects/pdfb/ While I've never used Japanese text, I think as long as you have a font for it, it should work. With these scripts, I've successfully created a script that writes text on top of a PDF document. Haven't tried Japanese fonts yet, but it looks possible. Thank you for the tip. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Taking body of an email and storing it in MySQL database
PHP List, I am working on a project now where I need to check a POP3 mail account, download any mails there, and store the body and headers of each individual mail as plain text in a MySQL database. I have downloaded the POP3 class which seems to be the standard class everyone uses for POP3 mail checking: http://www.phpclasses.org/browse/package/2.html I think I understand how to create an instance of the class and use it to check the email. The part where you log into the account isn't that complicated. But after that it becomes a little strange. It seems that emails are not mere text files, but have to be assembled line by line? I thought each email, and their headers, would be something I could just access, download, and pass along to MySQL. But it seems more complicated than that. Has anyone done something like this before? If someone could let me know how it is that I can create a body of text for each email (including the headers) so that I can then store it in the database, that would be awesome. Any advice would be much appreciated. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Taking body of an email and storing it in MySQL database
Richard, Thank you for responding. Sounds like you may have a MIME (an HTML email or one with attachments etc) email to decode. No, the mails should be in plain text format. I probably didn't describe my issue properly because I don't understand it fully. If I can assume all the mails I am receiving are in plain text format - which they should be because it is within a controlled environment - can I use PHP to pull out each email from the POP server essentially as a text file? I need to find out the sender and subject line, but other than that, the rest of it (including headers) I just want to store in MySQL. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Taking body of an email and storing it in MySQL database
Paul, Is there a decent tutorial anywhere on the net for the pop3.class.inc available on phpclasses.org? http://www.phpclasses.org/browse/package/1120.html Maybe I'm blind, but I just can't find anywhere a decent description or tutorial of what calls you can make to its functions. The documentation file has two sections in German and a terse section in English. I'm trying to figure out how to get each message and get their subject line, from address, and then based on those two pieces of information, I'll take the whole body and store them in the right place in a MySQL database. Just for reference, this is what I've built so far (I renamed pop3.class.inc to POP3.php): include('POP3.php'); $pop3 = new POP3(); // Connect to mail server $do = $pop3-connect ('xxx.x.com'); if ($do == false) { $message = $pop3-error; } $do = $pop3-login ('uuu', 'ppp'); if ($do == false) { $message = $pop3-error; } $status = $pop3-get_office_status(); if ($status == false) { die($pop3-error); } $count = $status['count_mails']; for ($i = 1; $i = $count; $i++) { // Here's where I hit a wall. // 1. Get the from address // 2. Get the subject line // 3. Get the header+body as one text file // 4. Store it in the database. } $pop3-close(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Taking body of an email and storing it in MySQL database
Paul, Thank you very much for responding. I'm not sure why you're attempting to do the above. According to the documentation, you should simply be able to do ... $pop3-save2mysql(a bunch of parameters); I'm not sure the parameters on the save2mysql() function give me the flexibility I need. I have to save to particular tables and change other fields in the database, determined by user data in the database and the from and subject field in the email. The save2mysql class seems to assume a certain database structure. Although, again, I could be wrong about that because documentation is lacking. However, you could set up a loop like this: for ($j = 0; $j count($msg); $j++) { if (strpos($msg[$i], 'Subject: ') == 0) // got the subject line if (strpos($msg[$i], 'From: ') == 0) // got the From: address line } Parsing the subject line and From: address is up to you. But there are plenty of PHP functions to search and parse strings. Thanks very much for the code you provided. I think that should be enough of a boost forward to get me to a new stage, and hopefully even take me to the end of this current problem. I'll see what I can do with it and then hopefully report back success. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Write Japanese text into an existing PDF
PHP List, I am looking for a way I can create a PDF file by overlaying text onto an existing PDF document. I have found three open source script sets that seem to do that, but I can't figure out exactly how they inter-relate. They are TCPDF, FPDI, and FPDF. From what I can tell, FPDI (which runs on top of FPDF) can overlay text onto another PDF, but I can't get any examples to work, so I am unsure of its stability. Also, I need to output Japanese text, and the documentation indicates it only supports Latin based fonts. TCPDF seems more fully featured and promises multilingual support. But for the life of me I can't find any single example of whether or not it can take an existing PDF and write text over top. Surely this is possible and has been done to death before. Can anyone direct me to a tutorial or sample script that I can use in order to set up this PDF generation script? Thank you for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Compare PHP settings of two different servers
Bob, Ben, David, Robert, Thank you all for responding. Just to recap, I'm trying to find out why I can write text into a PNG image on one server, but not on another. After much playing around, I have a list of the different configuration modules installed on the two servers. The lists below are lists of the modules *not* in common between them. From what I can see, none of the modules that the behaving server have that the misbehaving server doesn't has anything to do with fonts or images. So my suspicion is starting to be that maybe the problem is not in the PHP set up, but elsewhere. Before I move on to other possible solutions, I'd like to double check with more experienced eyes. Do any of the modules here affect text in PNG files? Misbehaving Server: '--enable-ftp' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo' '--enable-soap' '--enable-zip' '--with-apxs2' '--with-curl' '--with-curl=/usr/local/lib' '--with-freetype-dir=/usr/local/lib' '--with-mcrypt' '--with-mhash' '--with-openssl' '--with-pear' '--with-pdo-mysql' '--with-pdo-sqlite' '--with-sqlite' '--with-xmlrpc' '--with-unixODBC=/usr' Behaving Server: '--disable-pdo' '--enable-libxml' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-freetype-dir=/usr' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-libxml-dir=/opt/xml2/' '--with-mime-magic' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-xpm-dir=/usr/X11R6' And, just to note, *both* servers have the following: * '--with-gd' * '--with-ttf' * '--enable-gd-native-ttf' -- Dave M G http://tlug.jp/mediawiki/index.php?title=User:Dave_M_G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Compare PHP settings of two different servers
Bob, Thanks for replying. Another thought comes to mind. What text encoding are you using and what are the locale settings on those servers? I try to ensure UTF-8 is the only encoding used, as much as possible. Unfortunately, on the server that is misbehaving, it is the one where I don't have shell access, so I'm limited in how much I can poke and prod at its settings. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Compare PHP settings of two different servers
PHP Gurus, I'm currently having a problem with PHP writing text to a PNG image on one server. I have various web sites hosted on various servers, and on most of them, the script that generates the image is writing text properly. I have ensured that the same fonts are available on all the servers. My first guess was that the PHP environment on the misbehaving server was missing a GD module, like the TTF module or something. As far as I can tell by looking over the phpinfo() settings, the servers have all the same modules. But maybe I'm just not seeing it, because manually going over the settings is prone to human error. Is there a way I can take the output of phpinfo() from both servers and do a compare that will tell me what the differences are? Alternatively, if anyone has any suggestions on what might be a cause of not getting text onto an image, I'm open to any ideas. Thanks for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Compare PHP settings of two different servers
David, Robert, Thank you for replying. Just diff the HTML. Unfortunately it is not that easy. Even if the same PHP modules are present, if they are written into the page in a different place, they show up as differences. The same goes for all the HTML tags and everything else, so what I end up with is a ton of text, no more streamlined or easy to analyze than the original output from phpinfo(). I'm hoping there's a way more targeted way of discerning what settings one server may have that another server might not. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mozilla user agent escapes detection
Richard, Thanks for responding. http://www.phpguru.org/static/browser.html I may just do that. If it works out for my needs, I'll let you know. Really, right now I'm doing browser detection to simply sort incoming browsers into desktops, bots, and mobile. If I can get your script to do that, then sweet. By the way, another thing I'm trying to do is reliably test to see if a browser accepts cookies. I just looked through your PHP blog, and didn't see that specifically listed, but since I'm emailing you already, may I ask if you have a script that does that? Or a good recommendation? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Mozilla user agent escapes detection
PHP List, I have a script, part of which is taken from a script I found on the 'net, which tries to detect the user agent of the browser accessing the site. One of the reasons I'm doing this is to find out if the browser is a desktop or mobile. Part of the code looks like this: $ua = strtolower($_SERVER['HTTP_USER_AGENT']); $isDesktop = (strpos($ua, 'firefox') !== false) || (strpos($ua,'mosaic') !== false) || (strpos($ua,'msie') !== false) || (strpos($ua,'opera') !== false) || (strpos($ua,'mozilla') !== false) || (strpos($ua,'w3c_css_validator') !== false) || (strpos($ua,'w3c_validator') !== false); What's driving me crazy is that it successfully determines all the browsers listed there, *except* mozilla. I have a log file which alerts me when an unknown browser comes through my site, and it's chock full of messages telling me that a Mozilla based browser has come by. There are a *lot* of Mozilla based browsers. Some examples from my logs of the browsers slipping by my test: HTTP_USER_AGENT: Mozilla/5.0 compatible; Yahoo! Slurp HTTP_USER_AGENT: Mozilla/5.0 compatible; Googlebot/2.1 HTTP_USER_AGENT: Mozilla/5.0 X11; U; Linux i686 In each case, the strpos() should have seen the mozilla agent and not bothered logging it. It's not complicated code, especially considering it's successfully finding msie and firefox. I can't imagine why Mozilla would be different. Any suggestions? Is there something about my code right in front of my face that I'm not seeing? Any suggestions would be greatly appreciated. Thanks. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Forward slashes and header requests
Ashley, Thank you for responding. best way to fix it was to use $location = str_replace('//','/', $_SERVER['REQUEST_URI']); Unfortunately the trim() command I use seems to destroy all slashes anyway, so this doesn't seem to have an impact. Thank you for the suggestion, though. Anyone have any other ideas? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Forward slashes and header requests
PHP List, I have built my own CMS system, and I've just finished setting it up so that it sends a test cookie to see if the browser has cookies enabled. If it doesn't, it does URL rewriting to handle sessions. Part of this process involves reloading the page, and sending back a header to get it to go to the right page. In amongst the code, I have this line: header (Location: /$userRequest); $userRequest can sometimes be empty, such as when someone only types the domain name in their browser's URL field. Like, http://www.mynicesite.com;. But, I've learned that if I just do this: header (Location: $userRequest); Then the the browser displays nothing at all. There has to be at least something after Location: in the header() command. That's why I put the forward slash in, thinking that it would take people to the root directory of the site. It works for when people put nothing in the URL other than the domain name. And it works for every other page or directory on the site. But, I've also learned that if someone creates a link like this: a href=/click here/a ... then what happens is that the system gets confused about what directory it is in and will lose track of any files located by relative paths. CSS files and images are not found, and the page comes up completely unformatted. I've done a lot of experimenting, and one thing I tried was this: $userRequest = trim($_SERVER['REQUEST_URI'], /); ... so that I would take the slash back out of the URL when it came back. But it still doesn't work, so now I'm wondering if the browser is doing something different when it handles a single forward slash. Bottom line, I can't figure out why this: a href=/click here/a ... does not work with this: $userRequest = trim($_SERVER['REQUEST_URI'], /); header (Location: /$userRequest); Any suggestions or help would be greatly appreciated. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Kill Magic Quotes
PHP List, I am developing a web site that is hosted on a web server where I do not have permission to change the php.ini file. This server has magic quotes turned on. I'd like them off. I wrote two functions to detect when magic quotes is on, and to try and counter act its effects. But it does not seem to be working. It seems to have no effect, and I get slashes showing up in all sorts of output where I don't want them. Not only in data put into the database, but also emails sent to from the site contact page and other places. Here are the functions I created. Where have I gone wrong? public static function removeSlashes($string) { // Check if Magic Quotes is turned on. if (get_magic_quotes_gpc()) { // Remove escape slashes. return stripslashes($string); } // Return a string that has no escape slashes. return $string; } public static function restoreSlashes($string) { // Check if Magic Quotes is turned on. if (get_magic_quotes_gpc()) { // Add escape slashes. return addslashes($string); } // Return a string that has escape slashes. return $string; } Any advice much appreciated. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Kill Magic Quotes
Richard, Thank you for replying. If you can't change php.ini, and if it's Apache, you maybe can just turn it off in .htaccess, far faster and easier than a PHP function. I looked on the web and found this line: php_flag magic_quotes_gpc off ... and added it to my .htaccess file. But it doesn't seem to make a difference. I've set my scripts up so people can embed Google Maps on their pages. The problem I'm seeing now is that the output for the Google Map has all these additional double quotes that I don't know where they are coming from. Maybe it's not a magic quote issue? It looks like this: iframe width=\360\ height=\360\ frameborder=\0\ scrolling=\no\ marginheight=\0\ marginwidth=\0\... (trimmed for brevity) You are calling the removeSlashes, right? I believe I'm calling it everywhere there is some text being inputted or outputted. And, really, there is no reason for the restoreSlashes function to exist. If you ever think you need it, you're wrong. I guess that makes sense. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Kill Magic Quotes [SOLVED]
Richard, Try php_value instead of php_flag, though both should work for this one. Whoops... my mistake. Without going into overly complicated details, I hadn't tested the original suggestion properly. Turns out, so far as I can tell, both of these lines work for me: php_value magic_quotes_gpc off php_flag magic_quotes_gpc off Right now I'm using php_value, so I'll stick with that. This seems to have solved my magic quotes woes. Thank you Richard, Chris, Roger, Viraj, and the PHP list for responding. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Memory limit of 8 MB not enough
PHP list, I have a PHP script that resizes an image. It takes just about whatever size and shrinks and crops it down to 320X240. I've found that these days, it's not uncommon for people to take images straight off their digital camera, which can be 3000X2000 pixels in image size, even if the jpeg file containing the image is only 200 KB. When working with the image, it gets uncompressed and takes up a lot of memory. So sometimes I've seen an error in my logs that says: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 8000 bytes) in /home/public_html/Action.php on line 153. I contacted my web host provider, and they recommended increasing the allowed allocation limit in /etc/php.ini. Right now my allocation limit, assuming I'm looking at the right setting is 8 megabytes: memory_limit = 8M ; Maximum amount of memory a script may consume (8MB) What would be a recommended size? While I want to have enough to work with large images, I don't want to overload the server. Actually, I have no idea what the potential dangers are. Just on principle I think it's a bad idea to edit php.ini without some guidance. What should I set the memory limit to? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP gives session error on remote server, but not local test machine
PHP list, I have a large set of PHP scripts of my own design that outputs any errors to text log files. These scripts are deployed on a few different sites, at different virtual hosting services. On one, I keep seeing this error in my log files: Error Handler message: session_start() [a href='function.session-start'function.session-start/a]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' /home/domains/mydomainname.com/public_html/index.php 107 Before I show the content of index.php, I want to emphasize that no other virtual host produces this error. My home testing environment doesn't either. I have doubly ensured that the scripts are the same across all environments. So there must be something in the interaction of my scripts on that hosting service that is causing this error. Here are the contents of index.php, trimmed of most comments for brevity. Line 107 is where the last session_start() call is. My question is why would this code trip an error on one server, but not all? Thank you for any advice. --- code --- include_once '+site/Settings.php'; include_once 'Global.php'; set_error_handler(array('ErrorHandler','handleError'), E_ALL); // initialize the output tree. This is the structure that receives all the ouput and stores it in a tree form // based on the HTML structure HTML::initializeTree(); $userRequest = trim($_SERVER['REQUEST_URI'], /); if (Browser::supportsCookies()) { session_start(); } else { if (strlen($userRequest) != 0) { $sessionArray = Session::decodeSessionID($userRequest); if (is_array($sessionArray)) { session_id($sessionArray[0]); $userRequest = $sessionArray[1]; } else { $userRequest = $sessionArray; } } session_start(); } --- code ends --- -- Dave M G Articlass - open source CMS http://articlass.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP gives session error on remote server, but not local test machine [SOLVED]
PHP list, Solving my own issue: It turns out that some PHP scripts had an extra carriage return character at the end of the file. Once I removed these, the problem went away. Strange that it only happened on some servers, not others, but there it is. -- Dave M G Articlass - open source CMS http://articlass.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Importing and exporting from MySQL, escape slash problem
Richard, Jed, Thank you for replying. Richard said: It's possible that there is an .htaccess file in phpMyAdmin that has Magic Quotes on that is messing you up... The .htaccess file for phpMyAdmin says php_flag magic_quotes_gpc Off, so I guess that means I'm okay there. Other than that, it's specific to phpMyAdmin, so maybe ask those guys what they did... I joined their list through Sourceforge, but I haven't seen any mail from it, and any mail I send gets bounced back to me. I'm not sure what the issue is. Jed said: If you're having trouble importing a mysql dump using phpMyAdmin, it might be simpler not to use it, and use mysqldump instead. I suppose I'll have to if I can't get phpMyAdmin to behave. It's too bad, though, as phpMyAdmin is so convenient otherwise. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Importing and exporting from MySQL, escape slash problem
PHP List, MySQL List In my PHP environment, I have Magic Quotes turned off, and I use the mysql_real_escape_string() function clean strings of SQL syntax before inserting them into my database. So the data stored in my database does not have escape characters in it. Particularly, double and single quotes don't have slashes in front of them. This seems to work fine so long as I'm reading data into and out of the database from within my scripts. However, when I backup and import databases - I use the phpMyAdmin interface - they have escape slashes in front of every double and single quote characters. I'm not sure if it's on the export or import where they get added in. I've looked through the phpMyAdmin online documentation, and I can't see any option to control the presence of escape slashes. It seems to me that if it adds them in when exporting, it should take them out when importing. Or vice versa, but in either case be consistent. I just want my database to be exactly as it is before any export or import options. I'm a little muddled as to where I'm making the mistake. Can anyone advice on the best practice for preserving my database as is when backing up and restoring? Thanks for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Scripts are fast locally, but slow on remote server
PHP list, I have a set of PHP scripts that seem to be efficient and quick enough both on my home testing environment, and a few different web-hosting services I use. However, on one particular web-hosting service, there is often a very painful 10 second (!) lag when first loading up the scripts. This long lag time can sometimes be manifest not just on the first page loaded, but the second and maybe third as well. But then after the first initial pages are loaded, the site seems to speed up to what I would consider normal download pages for times. There are some pages on the site that are not driven by these PHP scripts, and they load up very quickly, indicating that only my PHP scripts are affected. So the problem seems to be, as far as I can tell, that something about my PHP scripts is combining with some setting of this one web-hosting server to create some kind of slowdown. Is there any way I can diagnose a situation like this to get to the root of the problem? Perhaps there are common discrepancies between server settings that I can look out for? Any advice would be much appreciated. Thank you. -- Dave M G Articlass - open source CMS http://articlass.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Scripts are fast locally, but slow on remote server
Per Jessen, Thank you for responding. Might this be a name-server issue? Maybe, but I don't think so. The reason I suspect that is not the case is because I can go first to a .html page on the server, and it loads up quickly. Then I go to one of my .php pages, and the slowdown occurs. If it were a name server issue, I would expect the slowdown to happen regardless of which page I load first. So, I guess to be more specific, the slowdown happens the first time I load one of my PHP scripts on this site, not the first time I access the site. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Writing text into images, and setting text size [SOLVED]
Rob, Thank you for helping me through this. '--enable-gd-native-ttf' '--with-ttf' This was the key information. I thought that having the GD modules installed meant I had TTF support. But after I saw that, I realized that TTF support was a separate module within the GD library. On my home Ubuntu environment, placing TTF support simply meant installing the right package from the repository (which I found in Synaptic by searching for PHP TTF). I'm hoping that TTF support is reasonably common on web hosting services, since I'm aspiring for my code to be portable. In any case, you've helped me get to the point that I needed to get to, so I am very grateful for your support. Thanks. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Writing text into images, and setting text size
Rob, Thank you for responding. Try the following: ... you load PrintImage.php into your browser and you'll get a nice gray rectangle with the word Works! in the center of it. If you don't get that... then you have a problem that is not related to path or to PHP per-se... Wow... thank you so much for providing that code to help me test my environment. I ran your script - with the corrections you provided - and did not get the text that says Works!. I've checked with various fonts, and checked that they worked in OpenOffice and other apps, so I don't think fonts are the problem. As for GD support, phpinfo() it says: GD Support enabled GD Version 2.0 or higher FreeType Supportenabled FreeType Linkagewith freetype FreeType Version2.1.9 T1Lib Support enabled GIF Read Supportenabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Supportenabled GetText Support enabled Am I missing a necessary module? Hope this helps It helps very much. Thank you. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Writing text into images, and setting text size
Casey, Thank you for replying. Try imagettftext(). I did, as explained: $font = '/usr/share/fonts/truetype/freefonts/FreeSans.ttf'; $imagettftext($image, 20, 0, $x, $y-10, $textColour, $font, $text); So my questions remain: 1. 'FreeSans.ttf' is in my /usr/share/fonts/truetype/freefonts directory. But specifying it doesn't seem to work. How do I get the system to find the font? 2. I need the scripts I'm writing to be portable, so can I be sure of what fonts will be available, and will I be able to locate them? 3. I'm not really concerned about what font it is, just that it's large and readable. If there are other options than what I've explored here, then I would be open to those too. Thank you for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Writing text into images, and setting text size
Andrés, Thank you for responding. Deploy the fonts along with your scripts... that's the only way I know. ... I do so for a custom CAPTCHA script I've made. This sounds like a good solution. I'm having a little trouble implementing it, however. I have what I believe is a freely distributable font called FreeSans.ttf, and I put it in a directory called fonts in the base directory of my site. However, this seems not to work: $font = 'fonts/FreeSans.ttf'; imagettftext($image, 20, 0, $x, $y, $textColour, $font, $text); Putting a slash in front to specify starting from the base directory - '/fonts/FreeSans.ttf' - does not seem to work either. Looking in the manual, it seemed that maybe I needed to set the font path with putenv: $path = realpath('fonts'); putenv('GDFONTPATH=' . $path); But this yielded no results. Am I still getting the syntax wrong somehow? Thank you for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Writing text into images, and setting text size
PHP List, I've been able to write text into an image using the default fonts available, with this command: ImageString($image, 5, $x - 20,$y-10, $text, $textColour); The problem is that the font that is identified by the index 5 is too small. But it seems that it can't be scaled in any way. So I thought I would try to specify a font and try something like this: $font = '/usr/share/fonts/truetype/freefonts/FreeSans.ttf'; $imagettftext($image, 20, 0, $x, $y-10, $textColour, $font, $text); But I'm clearly not doing things quite right, and I have some questions: 1. 'FreeSans.ttf' is in my /usr/share/fonts/truetype/freefonts directory. But specifying it doesn't seem to work. How do I get the system to find the font? 2. I need the scripts I'm writing to be portable, so can I be sure of what fonts will be available, and will I be able to locate them? 3. I'm not really concerned about what font it is, just that it's large and readable. If there are other options than what I've explored here, then I would be open to those too. Thank you for any advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Mysqli support - test or complain?
PHP List, Based on what seemed to be good advice to switch to using mysqli for interacting with a MySQL database, I built a content management system that uses mysqli for all it's calls. It works great on a lot of my servers. However, I just discovered that one web hosting service I use does not have mysqli enabled. I ran the phpinfo() command and they are running 5.2.5, but the configure command does not contain --with-mysqli. I would like the scripts I've written to be somewhat portable, but I'm unsure of whether or not I should assume that mysqli is in use. I see it as being a situation of essentially two options. One is based on the assumption that mysqli is as likely not to be available as it is to be installed. In this case I should write my scripts to test whether it exists and then use either mysqli or straight mysql commands as appropriate. If this is the way to go, what do I do to test for the existence of mysqli from within a PHP script? The other is to assume that recent installs and upgrades of PHP 5 should have mysqli because that's the currently preferred way of doing things, and therefore I should contact the web host and ask that they install it, or I find a different host. Which assumption should I be proceeding with? Thank you for any advice or assistance. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mysqli support - test or complain?
Richard, Per, Andres, Thank you for responding. If it were entirely my web site to dictate what to do with, I would just switch for a server that has mysqli available to me. However, in this one case, the web site is owned by a small, not very profitable group that has reasons to stay with their current webhosting service. I want to support them if possible. Richard said: Alter your program to support both - use mysqi if it's avilable, mysql if it's not. How exactly do I test for the presence of mysqli from within a script? Or are you saying I have two different versions of my script? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mysqli support - test or complain? [SOLVED]
Zoltan, Per, Richard, Chris, Daniel, Larry, Thank you for responding. I have created a method in the class that handles my database connections that will first test on extension_loaded(mysqli) before connecting to the database. Then I store the result in a session variable for reference, so future calls will use the correct mysqli or regular syntax. Thank you for helping me to find this solution. My scripts are that much more portable now. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic question - PHP usage of SVG files [SOLVED]
Larry, Thanks for your advice. With the XML editor available within PHP, I've made a small script that can extract the point data inside an SVG file, and store them as an array of points. That array can then be used to draw and fill shapes in a PNG image. And since they are stored as an array, I can do a little math on them to manipulate their scale and whatnot. The interpolation between points gets lost with this method, but in this case, I can get by with straight lines. Thanks for helping me to see the value in using PHP's XML functions. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic question - PHP usage of SVG files [SOLVED]
Casey, There is no SVG support in PHP, as far as I know. Thank you. That clears things up. I'll just go with PNGs then. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic question - PHP usage of SVG files
Larry, Thank you for responding. I think you missed the point. SVG is just text. ... There's no need for SVG support per se, as SimpleXML provides all you need anyway. I did miss the point - thanks for setting me straight. However, I'm still unsure about using SVGs. On the one hand, what I'm using as source files are originally in SVG format and I want to be able to dynamically resize and scale them without loss of clarity. But, after they have been resized and scaled, then I think I need to send the resulting image to the browser in some raster image format. Indications are that SVG support on browsers is still not as uniform as PNG or other raster graphics formats. At that last step, assuming that I have manipulated the images to my satisfaction with SimpleXML, can I then output the result in PNG or JPG with PHP? I'm not so sure this can be done. The tricky part is that I am building PHP scripts that could be deployed on servers with different PHP settings, so I'm not confident that I can rely on PEAR or ImageMagick functions being present. Are they standard on PHP 5? Forgive me if my questions are clueless to the point of making the questions unclear. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Basic question - PHP usage of SVG files
PHP list, I have some images that are in SVG format. What I want to do with them is manipulate them by resizing and overlaying one on top of the other. I do this frequently with PNG images, and I could first convert these images to PNG before manipulating them in PHP. However, I'd like to preserve line quality by keeping them as SVG until the last moment. I can't see on the online documentation if SVG is supported and if it requires different commands than raster image formats. What is the support for SVG in PHP, and where is the online documentation for it? Thank you for your help. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Mime Magic functions - how standard are they?
PHP List, I would like to set up a function within my system that can test a file that a user has uploaded and determine what kind of file it is. My intention is to only handle a fairly small number of common file types*, so I don't think I need to build anything too robust. Of course, I checked php.net, but was almost immediately confounded by what seems to be a transition from mime_content_type to Fileinfo. My confusion lies in the fact that on the one hand mime_content_type seems to be in the process of being depreciated, but at the same time, the Fileinfo functions seem to rely on PECL extensions which don't seem to be standard in every PHP installation. At least, it seems like the PECL extensions are not present in my testing environment, which use default installation settings (via Ubuntu Feisty repositories). When I tried to emulate the example on this page: http://php.benscom.com/manual/en/function.finfo-open.php ... It gave me an error indicating the class finfo could not be found. I'm trying to build a system that will hopefully be portable without anyone having to reconfigure PHP in any way to get it running. So, ultimately, what I'm wondering is, what should I be using in order to determine file MIME types that will be the most commonly installed on servers with PHP? Thank you for any advice. * The file types I will test for are most likely to be the following: .txt, .pdf, .png, .gif, .jpg, .mp3, .ogg, .doc, .odt, .zip, .gz... maybe that's it. -- Dave M G Zend Studio 5.5 Ubuntu 7.04 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Strip numerical indices from array [SOLVED]
Larry, Thank you for responding. ... you want to be using mysql_fetch_assoc() instead... Thank you, that helps me achieve what I need. Or, better yet, use mysqli_ ... if you're running PHP 5 (which you are, right? Yes, I am running PHP 5. However, this mysqli usage is clearly not as simple as replacing every instance of mysql_ with mysqli_. I will look into it further and see if I can migrate to using mysqli_ somehow. Thank you for the advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Strip numerical indices from array
PHP General list, I've got an associative array that also includes a numerical index. The numerical index was automatically generated from the mysql_fetch_array command, so it the values are the duplicates of the associative key names. Is there a way to simply strip off the numerical index, leaving only the associative key names? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Includes eating up my time [SOLVED]
David, Thank you for responding. __autoload ... which basically only loads classes when they are required. Yes, this is exactly what I needed. Not only was I already on PHP5, but fortunately I had also already been building my classes so that it was one class per file, as __autoload requires. So this was possibly the easiest and most effective change I've ever implemented. And the results were impressive. The Zend profiler reported that I went from 500 to 800 milliseconds per page request down to 40 to 60 milliseconds. Occasional database connections raised the time now and again, but I think I have a handle on that. Thank you for pointing that out to me. Just the right solution. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-16-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Includes eating up my time
PHP general list, This is probably obvious to people who are good at PHP, but I'm I have a PHP based CMS (content management system) built, which has grown and become quite robust. It's now spread out over about 30 files, and each file represents one class within the object oriented design. Each are a couple hundred lines of code, and two or three of the most critical classes are over a thousand lines of code. While first building it, I didn't really anticipate quite that many files. What I did is have a file called includes.php, which list all the files to be included. Then I in turn included includes.php at the beginning of my index.php file. Every page request passes through the index.php file, so that basically means every single file is included at the start of every new page request. I'm using Zend Studio, which has a profile option, which shows how long it takes for my PHP scripts to complete a request. It has a breakdown showing percentages of which scripts are using that processing time. Currently, my processes are taking under a second, but they can be around half a second or more. Although it all happens too fast for me to really notice as a person, it seems to me that a half second of processing time might be kind of long and lead to scalability problems. My first question is: Is a half second too long? I'm pretty sure it is, but maybe I'm just being paranoid. What do people consider to be acceptable time frames for processing a web page similar to what Wikipedia delivers? Most of the time is taken with the includes. Anywhere from 60% to 90% of the time it takes to process my scripts is coming from the includes.php file. I read somewhere that it's not a good idea to have more than 10 includes in any one place. I'm fine with trying to break up my include requests, but I'm unsure as to how. As each function in each class passes around objects, it's not clear from looking at the code which ones are used at any one time, so I'm unsure how to efficiently include only the necessary classes. My second question is: Is there a systematic way of determining how to incrementally include files that people use? Or is it just a constant process of testing and checking? Thank you for any advice. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-16-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reformatting the URI on return to the browser
Robert, Thank you for responding. But to expound... :) Wikipedia issues a 301 (permanently moved) response header (don't tell Richard Lynch ;) thus redirecting your browser to the underscore version. I won't tell Richard Lynch if you don't want me to. Now that you've clarified what I'm looking for, I was able to dig up a little code on the 'net, at this site for instance: http://www.beyondink.com/howtos/301-redirect.html Where I got this code: ?php header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.new-url.com/'); ? Of course I modified it slightly to fit my needs. But basically it seems to work like a charm so far. Thanks for all your advice and assistance. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Reformatting the URI on return to the browser
PHP, I've implemented friendly urls in my PHP scripts, so that people can type in things like: http://website.com/Cats And Dogs ... and they'll be taken to the right page. However, when they get to the page, the url will read: http://website.com/Cats%20And%20Dogs Not so pretty. I've noticed that Wikipedia will alter the URI to become more readable, by replacing the spaces with underscores, like so: http://wikipedia.org/wiki/Cats_And_Dogs I'd like to be able to do that with my system, but I can't quite figure out where in the process of getting a URI request and returning a page that the URI will get set. Can anyone help me with figuring out at what point I can gain control over the URI sent back, as Wikipedia does? Thanks for any advice. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Going from simple to super CAPTCHA
Robert , Thank you for replying. No, PHP can do it. If you can work with pixels (and you can) then you can do any advanced mutation of an image... the only issue is how long it takes to perform the mutations. That's good to know. I think I can live with a little server time to generate the images, so long as they work well. Check out the freecap code perhaps I'm assuming you mean this one: http://www.puremango.co.uk/cm_php_captcha_script_113.php Good CAPTCHA - bots can't figure it out Bad CAPCTHA - bots can figure it out Well, yes, but what exactly determines that is not obvious to me. I came across this page: http://sam.zoy.org/pwntcha/ ... which conveys a feeling that some CAPTCHAs that look good actually aren't. According to this page, the Yahoo CAPTCHA image, which looks quite minimal to me, is actually one of the better ones. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Double checking - I should turn off magic quotes
David, Thank you for replying. The way you write that makes me hope you understand how mysql_real_escape_string should be used. You do understand that you don't run it on the query, rather on the individual string variables that will be passed to the query. Thank you for your concern and clarification. I do understand the distinction, though, and although my description was terse, what I meant was that the content that is placed within the MySQL queries are screened with mysql_real_escapte_string, but the MySQL syntax of the query is left alone. I'm pretty sure if I hadn't made that distinction, my site would have malfunctioned immediately. Thank you for following up. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-16-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Going from simple to super CAPTCHA
PHP General List, With a little help from the web, and help from this list, I have a simple CAPTCHA image that works within the content system I'm building. But it's *really* simple. Basically white text on a black background, with a couple of white lines to obscure the text a little. I'm pretty sure that in its current state, my CAPTCHA image could be cracked by OCR software from the 1950s. So I'm hoping to take it up to the next level. I might be able to figure out how to add more lines, more colours, and those kind of basic changes. But what I definitely can't comprehend is how some CAPTCHAs have that really warped and distorted text. Is that possible with PHP? Do I have to make a library of pre-warped text images or something? Is it possible to make backgrounds that are really crazy with textures and gradients. Would that also rely on a pre-built library of images? Can someone maybe point me to an online instructional on how to get a CAPTCHA image that really works? Tips on what differentiates a good CAPTCHA from a bad one would also be really sweet. Thank you for any advice. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is the GD module standard? [SOLVED]
Tijnema, Greg, Robert, Thank you all for your advice. After the responses here convinced me that the GD libraries should be expected, I've contacted my hosting service to inquire why it's not already installed. My hosting service allows me to make custom configurations to PHP. Fortunately it turns out it's only a matter of making a check box selection and then clicking a button to install. Thank you for helping me understand what to expect out of a normal PHP installation. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Double checking - I should turn off magic quotes
PHP General, I've read on the manual that it's preferred to code with magic quotes off and to instead escape the data at runtime, as needed: Recently, while configuring my PHP so as to install the GD libraries, that the default option was to have magic quotes turned on. I just want to double check here what to do. Should I disable magic quotes on my server? Also, I'm developing code that I hope others can use. For the purposes of portability, is it safe to assume that most environments will have magic quotes off, and build for that? So I should disable magic quotes on my testing environment and do my own escaping? While I'm asking about escaping, is converting characters like apostrophes and ampersands to hex characters before storing them in a MySQL database a safe way to go? Thank you for any advice. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Double checking - I should turn off magic quotes
Robert , Thank you for your quick reply. If it's okay, I'd just like to clarify the points you raise. I just want to double check here what to do. Should I disable magic quotes on my server? Not unless you're certain you don't have any script that rely on magic quotes. If you do, then they will become open security holes. The only scripts I have are the ones I put there myself. So if I conform to the no magic quotes standard, then I should be safe, right? Also, I'm developing code that I hope others can use. For the purposes of portability, is it safe to assume that most environments will have magic quotes off, and build for that? No, you should check the ini setting in your code and react accordingly. Sorry, I don't quite follow you here. If I turn magic quotes off on both my testing environment and my server, as is preferable according to the manual, then my ini file will conform to that. But I don't see how that relates to the portability of the code. As much as possible, I'd like to have others be able to run my scripts with minimum hassle. If I make my development environment and my own web hosting server conform to the preferable set up, but most servers default to having magic quotes on, then won't my code break on most people's servers? So I should disable magic quotes on my testing environment and do my own escaping? Yes. Okay... but I'm still confused as to how this impacts the potential for my code's portability as described above. While I'm asking about escaping, is converting characters like apostrophes and ampersands to hex characters before storing them in a MySQL database a safe way to go? No, use the proper escaping mechanism offered for your particular database. Since my database is MySQL, does that mean using addslashes() and stripslashes()? In other words manually doing what magic quotes was doing automatically? Just for my own education, is it insecure to use hex codes to store apostophes and other special characters in the case of MySQL? Can someone inject a workable MySQL command into my database if all apostrophes and other non-alphanumeric characters are converted to hex? -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Double checking - I should turn off magic quotes
Robert , PHP General, Thank you for replying and explaining the situation clearly. Neither! It means using mysql_real_escape_string(): http://www.php.net/manual/en/function.mysql-real-escape-string.php I have now made it so each and every queries to the database pass through mysql_real_escape_string. I've also turned off magic quotes on my host and on my testing environment, and made it so my code tests for the existence of magic quotes before adding and stripping slashes. I was wondering if there are some recommended tests I can try to see how well I am protected against MySQL injection. I was searching via Google because I thought I had seen before a site that listed 10 common injection attacks. But I can't find it now, and seem to be only coming across proprietary software for sale. Can someone recommend some MySQL code that I can use to test my code? -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Is the GD module standard?
PHP General, I have been using the imagepng() function in my local testing environment for a while now to make CAPTCHA images. In my testing environment, I hadn't done any customization to my PHP set up. I went with the default set of installation options that Ubuntu offers for a LAMP server. Recently, I uploaded my site to a web hosting server, and the CAPTCHA would not display. At first, I didn't understand that it was a module issue, because I thought the imagepng() function was standard in PHP. However, by using the phpinfo() command on my hosting service, I realized they don't have the GD module installed. So my assumption that imagepng() will be available on any standard installation of PHP is wrong. However, I'm surprised that it wouldn't be as common as, say, the MySQL module. Is it that my Ubuntu installation comes with an unusual amount of bells and whistles? Is it that my web hosting server is lacking in what can be expected for standard PHP features? I want to write code that most people can expect to run on their hosting services without having to reconfigure their PHP installation. So, can I expect that most servers would have the GD module? If not, what do people usually do to manipulate images? Thank you for any advice. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Confused about how exactly to output image using imagepng function [SOLVED]
Robert, Zoltan, Stephen, Tijnema, Thank you for your responses. I did take some code off of the internet, but I had to modify it to work within the context of my general system. The explanations offered here have helped me achieve that. Thank you all for your insight and help. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Confused about how exactly to output image using imagepng function
PHP list, I've looked at the manual entries for imagepng() and imagecreatetruecolor() functions for helping me to create a temporary image for a CAPTCHA system. However, I'm clearly messing up, as what I'm outputting is a bunch of ASCII gibberish to the screen. What I think I need to do in principle is first create the image with imagecreatetruecolor(), then define it as a PNG (?), then display it. So I've got something like this: $image = ImageCreate($width, $height); ImageFill($image, 0, 0, $black); echo 'img src=' . Imagepng($image) . ' height=' . $height . ' width=' . $width .' alt=captcha /' . \n; ImageDestroy($image); As mentioned, this isn't working, so there's a fundamental concept about how PHP creates and displays images that I'm not getting. I'm trying to output an image that, ideally, won't be stored as a file. Or, if it has to be a temporary file, to delete it immediately after displaying it. What part am I not understanding? Thank you for any advice or information. -- Dave M G Ubuntu Feisty 7.04 Kernel 2.6.20-15-386 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What determines the relative directory, and can I control it?
Sancar, Tijnema, Logan, Richard, Thank you all for your replies. I kind of suspected that this was a client side issue. But I thought it was worth fishing for ideas since there are many on this list who are a lot smarter about PHP than I am. I might adopt something similar to Logan's $path solution, if it ends up looking more friendly than a full path name. That will be dependent on a few other settings in the code. Sancar, I appreciate where you are coming from in that designers shouldn't be afraid of having to write a simple path. However, I'm not so much trying to protect them from knowing stuff. It's more that I want to be able for a web site administrator to be able to open a directory for FTP access to a designer so that the designer won't have access to the rest of the site's files. For security's sake. In such an instance, the designer won't know where his directory is, and ideally wouldn't have to know. Richard, I've looked into Joomla, Wikipedia, and Wordpress, and actually I think templates are a terrible idea. My system is going to avoid templates as a design solution. Who knows, maybe one day people will like my approach better. Or maybe not. In any case, I think I've got an approach that may suit the needs of some better than the other systems. At the very least, I like it (insert emoticon here). -- Dave M G Ubuntu 7.04 Feisty Fawn Kernel 2.6.20-15-generic Pentium D Dual Core Processor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] What determines the relative directory, and can I control it?
PHP Users, I am developing a content management system, and one of the goals is to separate out the design entirely from the PHP scripting and content. All the PHP scripts which contain the logic that drives the site are all in the web site's root directory, where the main index.php is located. The site uses an .htaccess file that creates user friendly URLs, so basically every time a user does anything on the site, it goes through /index.php. The intention is for the designer of the site to only have access to a subdirectory of the site called layout. If the designer wants, he or she can have multiple styles, which would each be in their own subdirectories. So, for example, there might be a /layout/styleOne directory, and a /layout/styleTwo directory. The way a designer builds a style is with a file called layout.php. This file contains blocks of HTML code that the designer can manipulate in order to customize the layout of the site. For example, that file would be located at /layout/styleOne/layout.php. Right now, if the designer of the site wants to make a call to an external CSS style sheet within layout.php, the designer has to write in the whole path, relative to the index.php file. For example: style type=text/css @import /layout/styleOne/style.css; /style But I'd like to make it so that the designer doesn't need to ever think about paths, and can state the path to the CSS file relative to layout.php, and not relative to index.php. Like so: style type=text/css @import style.css; /style What happens is that index.php includes a file called include.php. That file in turn includes all the PHP scripts on the site. That file includes another file called Page.php which has a way of including layout.php depending on what style the page needs. For example, styleOne or styleTwo. That's a long linear string of includes, but bottom line is, if I'm correct, that the index.php ultimately includes layout.php, and layout.php therefor acts as if it were in the same directory as index.php. I hope I have described the situation adequately. My question is, as implied above: Can I somehow manipulate any of the PHP scripts involved so that the HTML within layout.php will look first in it's own directory for inclusion of files, such as CSS and javascript and anything else? Thank you for your time and assistance. -- Dave M G Ubuntu 7.04 Feisty Fawn Kernel 2.6.20-15-generic Pentium D Dual Core Processor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Mailing list combined with PHP based forum
PHP Users, I'm creating a PHP based forum, and what I'd like to do is have it work so that people can view and read the information via email, just like a mailing list. Yahoo! Groups does this, so I know this sort of thing is possible in principle. But so far as I can tell, open source PHP based forums, like phpBB and Simple Machines, don't commonly have this feature. Perhaps it's not possible with PHP? I would imagine this is accomplished with a Cron job that checks an email account and passes the messages to the PHP system for parsing into the forum. Can anyone start me off with some tips as to how, and if, this might be possible? Thanks for any advice or informaiton. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Passwords suddenly not working
PHP List, I have a few scripts that have been around for a while. In one, is a simple login function: $query = SELECT * FROM forum_members WHERE memberName = ' . $username . ' AND passwd = MD5(' . $password . '); $result = mysql_query($query); This was working fine, but recently I haven't been able to log in. I think the only thing that has changed is that on my hosting service, they recently upgraded to PHP 5.1.6. (MySQL is 4.1.21, but I think it's been that for quite a while) Is there any potential for PHP 5.1.6 to handle things different when it comes to MySQL queries, post data, or anything? I thought it might be that I still had $HTTP_POST_VARS for some of my variables, but I changed them all to $_POST, and it still doesn't work. I don't get any errors or anything. My own code is not very sophisticated for error reporting. But I'm not getting any PHP syntax errors of any kind. If I run the SQL code by itself at an SQL command prompt, I get results back, so I don't think the SQL is failing. Are there any gotchas in the upgrade that I might be missing? I can't think of anything else that could be a culprit (though of course I'm open to suggestions). Any advice would be much appreciated. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Storing objects in sessions recursively
Vincent, Jochem, Thank you for replying. The issue turned out to be my Article class took arguments in its constructor, which was unacceptable because the argument could not be serialized when being passed along during the session. By adjusting my object so that the constructor takes no arguments, and then creating a new method on the object to do what the constructor did previously, the problem was solved. That explanation may be confusing, but that's because I don't fully understand serialization myself yet. All I can say for sure is that the problem was definitely a serialization issue. -- Dave M G Community Moderator -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Storing objects in sessions recursively
PHP List, I have a class called Session, which creates an object stored in the $_SESSION variable. That object in turn holds on to a User object which keeps track of the activity of the individual user who has logged in and is using the web site. Then the $user object in turn holds on to an Article object, which keeps information about web content that the user is editing, previewing, and viewing. The problem is that the article object keeps getting lost as the user clicks from page to page. I'm hoping someone can explain to me why this might be happening. As far as I can understand it, an object is basically just an array, and an object that owns an object as a member variable is just like storing an array in an array. I can't see any reason why there would be any limit to how many levels one could go down. So I'm assuming there's no restriction on how many levels of objects owning objects there can be. As for the code itself, I hope I don't strip out any key details, as it's all spread out across many classes. But here's what the basics of it look like: In the User class, I have this method: public function setCurrentArticle($currentArticle) { $this-currentArticle = $currentArticle; } In the Article class I have this line: Session::getSession()-getUser()-setCurrentArticle($this); In the Session class I have: private static $session; private $user; public function __construct() { $this-user = new User(); } public function getUser() { return $this-user; } public static function getSession() { if (!isset($_SESSION['session'])) { $_SESSION['session'] = new Session(); } return $_SESSION['session']; } I may have missed a detail in trying to keep this brief and readable. If so, please let me know and I will try to provide it. Thank you for any advice. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Upload not finding directory to write to.
PHP List, I had a file upload script which was working fine. Then, because of other needs, I changed my local Apache settings so that my local web site directory structure behaved the same as they do on my web hosting service. What I mean by that is that before, I would access my local web sites by going to their directories within the localhost (/var/www) directory: localhost/web_sites/web_site_one/index.php Now I just go to: web_site_one/ If i create a link that says a href=/link/a, it goes to the root of the web site, where the index.php is. Within that root directory, I have a directory called image, where I'm trying to put my uploaded image files. The destination file location should then be /image/, shouldn't it? My code looks like this: $fileLocation = /image/ . $_POST['name']; if(move_uploaded_file($_FILES['file']['tmp_name'], $fileLocation)) { chmod ($fileLocation, 0777); } $_POST['name'] is a name for the file that the user has entered. But this now gives me an error that it can't open a stream to the destination. I also checked to make sure that the image directory has fully open permissions, and it's currently set to drwxrwxrwx, or 0777. Am I missing some fundamental issue with directory structures on an Apache server? -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Ensuring all links go to index.php [SOLVED]
Edward, Roman, Jochem, Lowell, Kreme, Thank you for your explanations. Based on what was said here, I understand that the issue was setting up my local computer's Apache server to treat my directory hierarchies as they would behave on my hosting service. With the help of my local Linux user's group, I was able to edit my local Apache configuration files to get the right setup. As was mentioned here, it's not a PHP issue per se, but now I can, in PHP, get to my root web directory by simply preceeding any relative link with a forward slash. Thanks for your time and advice. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Setting try and catch to use my own error handler
PHP List, I have a system where the code parses the URL and creates objects based on the classes named in the link. In order to prevent a user typing in a URL that contains an object that doesn't exist, and getting an error, I'm trying to set up an error handler class, called ErrorHandler, that will handle it. I set the error handler to be my own, and then put a Try and Catch around the part of the code that set_error_handler(ErrorHandler::handleError()); try { object = new $urlParts[0](); if (!empty($urlParts[2])) { $object-$urlParts[1]($urlParts[2]); } else { $object-$urlParts[1](); } } catch (Error $e) { echo Sorry, the web page you are looking for can not be found.; } Inside my ErrorHandler, I have this: public static function handleError($errno, $errstr, $errfile, $errline) { echo Hey dude! Error! . $errno . $errstr . $errfile . $errline ; } However, I get errors saying that the arguments for handleError don't exist. Shouldn't they be automatically passed to my own error handler? Thank you for any advise. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] array_walk, or array_map, or foreach?
PHP List, I took a snippet of code right off the php.net site to use trim on all the elements of an array. Theoretically, it should test if the element in an array is in turn another array, and break it down to the next level until it gets to a string it can use trim on. This is the code: public static function trimArray($array) { if (is_array($array)) { array_walk($array, trimArray); } else { $array = trim($array); } return $array; } The function exists inside a static class called Utility where I keep all basic utility functions. I don't know if it's the fact that it's in a static class that makes a difference, but I've tried the following variations on the line with array_walk() in it: array_walk($array, Utlity::trimArray) array_map(Utility::trimArray, $array) array_map(trimArray, $array) I've even tried accomplishing it with a foreach(), but no matter what I do, it doesn't work. As it walks through the array, it seems to trim a copy of the element in the array, trim that, but leave the original array untouched. What am I missing here? -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Ensuring all links go to index.php
PHP List, This problem is a little hard to describe. Please forgive me in advance if it's not clear. I have set up my .htaccess file to work with my PHP script to create friendly URLs. For example, the URL mysite.com/user/login will take the user to a page where a user logs in. It does this by stripping everything out except user and login. It takes user and creates a user object, and then passes a login method to that class to take the user to the login page. Somehow, in this process, the local URL is becoming mysite/user, even though I'm just using that user designation to drive the creation of objects from classes. So, for example, I have a link to logout which is simply href=user/logout. But when I mouse over it, and look at the status bar at the bottom of my FireFox browser window, it says that the link points to: mysite.com/user/user/logout That URL, obviously, doesn't work for my system. It tries to make a User object and call a user method which doesn't exist. So... my question is, why is the /user portion of my URL being retained as a directory? I thought it had something to do with setting headers. I want everything to operate through the index.php file in my root directory, so I thought I could do that by putting this at the top of the index.php page: header(Location: /); Or: header(/local/server/www/directory/); Bottom line is, how do I ensure that all links and user requests through the URL end up going to the index.php in my web site's root directory? I hope this question is clear enough, and thank you for any and all advice. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Setting PHP to use SMTP
David, Thank you for your response. If you are on *nix and want to send mail via SMTP, you need something like http://phpmailer.sourceforge.net/ I have looked at phpmailer, but it's way over featured for what I want to accomplish. The tutorial they link to on their site, 11 pages long and full of settings I don't need, really turns me off. Is there no way to simply force my PHP emails through SMTP? I'm happy about everything else with my email set up, so surely there's a way to handle this one thing. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Setting PHP to use SMTP
PHP List, In an effort to make emails that I send through PHP scripts not be mistaken for spam, it seems that one thing I need to do is make sure that the emails are sent via SMTP. Right now, if I check my PHP generated emails with Spamassassin, it says: -0.0 NO_RELAYS Informational: message was not relayed via SMTP It's not deducting points, but I think the fact that it mentions it indicates I might be better off using SMTP. Looking at phpinfo, it says this about my PHP/SMTP settings: sendmail_from no value no value sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i SMTP localhost localhost I take this to mean that I don't have a default from address, but that it knows where my SMTP server is. However, the last variable, where it's set to localhost, is not so clear to me. Does this mean PHP is using the SMTP server on localhost? Does this need to be changed in order for PHP to actually send via SMTP since it doesn't seem to be doing so now? Beyond that, I have some follow up questions: My virtual hosting service is the kind where I have two IP addresses, and I can add as many domain names as I want to my account. Does that mean that if I set a default email address in sendmail_from that it will apply to all my domains? Is there a way to localize the setting on a domain by domain basis? Or is this a question I need to take to my hosting service provider? And last... how exactly do I set the variables? Do I have to manually edit php.ini and then restart Apache? Is there a command I should be running? Thank you for any and all advice. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Working with overly aggressive anti-spam measures
Travis, Chris, Thank you for your advice. I've installed spamassassin and I'm using it to monitor how well my PHP generated emails rate as spam. So far, I'm not doing well. I have two main issues so far: 1. Spamassassin says: Spam detection software, running on the system homebase, has identified this incoming email as possible spam. [...] Content analysis details: (0.3 points, 5.0 required) pts rule name description -- -- 0.3 AWLAWL: From: address is in the auto white-list I looked up about auto white-lists on the net, and it says that it's a comparison between the current and previous emails. But for testing purposes, I don't really want it to compare against previous emails, since previous test emails would be spammier and bias spamassassin the wrong way. How can I compensate for this? 2. I've attempted to add the Return-Path headers to my headers, like so: $headers = Return-Path: [EMAIL PROTECTED]; $headers .= From: Tokyo Street Hockey Association [EMAIL PROTECTED]\n; $headers .= X-Sender: [EMAIL PROTECTED]; mail($member, $subject, $content, $headers); And yet, when I look at the headers of the email that's being generated, it says: Return-Path: [EMAIL PROTECTED] Received: from server.mywebhost.com (ns1.nameserver.com [123.123.123.123] (may be forged) (Note that I've changed the names of servers and the DNS just to keep some info private) Why are my attempts to set these headers in PHP not taking effect? -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Working with overly aggressive anti-spam measures [SOLVED]
Travis, Richard, Chris, Thank you for your helpful advice. I've managed to set the Return-Path correctly now, and Spamassassin is now only giving me the whitelist error, which I don't think I'm going to get rid of. It took me a little while to realize that the Spamassassin always says that an email is possible scam if it has any score above zero, but it takes a score of 5.0 to actually be deleted as spam. I checked through a bunch of emails in my inbox, and all of them got at least some score, usually between .5 and 1.5, even though they were all legitimate emails. So compared to other emails I'm getting, I'm scoring very low at 0.2. My emails don't use HTML, don't have any common spam key words, and have correct spelling and grammar, so it all helps establish my email's legitimacy. Here is the PHP code I'm using: $fromAddress = [EMAIL PROTECTED]; $fromName = My Name; $headers = From: . $fromName . . $fromAddress . \n; $headers .= Reply-to: . $fromName . . $fromAddress . \n; $extra = -f . $fromAddress; mail($toAddress, $subject, $content, $headers, $extra); Thank you all for your time and expert information. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Working with overly aggressive anti-spam measures
PHP List, I run a few various social groups, and with each one I keep in contact with members by emailing them short newsletters. All my user information is stored in a MySQL database. I use PHP to get the relevant contact information, and use the mail() command to send out the emails one by one, so that each email is a little personalized. I've used this system for many years now with no problems up until now. What has changed, though, is that in recent years, anti-spam measures have become so aggressive that more and more people who sign up to my groups complain that they never receive the emails. A lot of the times, after they alert me to the issue, I can educate them a little about the anti-spam measures they most likely have on their system, and walk them through how to make it so that my newsletters go through. However, that is clearly not enough. To shorten a story that has already gone on a little long, it's come to my attention that part of the reason that my emails may not be getting through are because the headers are not sufficiently legitimate looking enough to bypass some server side anti-spam measures. Things like Return-Path are being set so that they look like they come from an email address that begins with the username nobody. If possible, can anyone help me with creating the PHP code that will make an email as legitimate as it can be? I know I can't totally prevent my email from being marked as spam (after all, if it were possible, all the spammers would do it). But as much as I can prevent anti-spam measures getting a false positive when testing my email, the better. Here is the PHP code I currently use (trimmed for clarity): while ( $member = mysql_fetch_row($mysqlResult) ) { $subscriber = $member[0]; $email = $member[1]; $subject = Report for . date('l jS F Y'); $mailContent = This is an email to . $subscriber . at . $email . .; $fromAddress = [EMAIL PROTECTED] mail($email, $subject, $mailContent, $fromAddress); } And here is what the headers for an email from that code looks like: -Account-Key: account5 X-UIDL: UID497-1152485402 X-Mozilla-Status: 0001 X-Mozilla-Status2: Return-path: [EMAIL PROTECTED] Envelope-to: [EMAIL PROTECTED] Delivery-date: Sun, 03 Sep 2006 14:22:42 -0700 Received: from nobody by server.myhostingservice.com with local (Exim 4.52) id 1GJzQQ-0005pA-Mz for [EMAIL PROTECTED]; Sun, 03 Sep 2006 14:22:42 -0700 To: [EMAIL PROTECTED] Subject: Report for Monday 4th September 2006 From: [EMAIL PROTECTED] Message-Id: [EMAIL PROTECTED] Date: Sun, 03 Sep 2006 14:22:42 -0700 Which parts are key to change, and how? Thank you for any and all advice. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using a variable to call another variable [SOLVED]
Martin, Tedd, Robert, Christopher, Thank you all for your advice and examples. I had not been aware that it was possible to simply add another $ ahead of the variable, to make a variable of the variable's name. And especially thank you for expressing an example in terms of a class and method, which is my ultimate intent with this process. I will also make sure to name my variables with at least one leading alphabet character. Thanks for the warning. All your time and expert advice is much appreciated. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Using a variable to call another variable
PHP List, I have a list of variables: $001 $002 $003 $004 And what I'd like to do is have a function which will select and return one of them. Something like: public function returnVar($n) { return $(somehow n is made to reference the name of the variable); } And then in later scripts I can call anyone of the variables by saying returnVar(001) Or something like that. I've been scratching my head on how to do this for a while. I thought the answer might lie somewhere in call_user_func(), but even if it is I can't determine how. Any advice would be much appreciated. Thank you for your time. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strip slashes from beginning and end of string in one expression
PHP list. This is another regular expression type of question. The very handy PHP function trim() takes excess white space off the beginning and end of a string. I'd like to be able to do the same thing, except instead of white spaces, trim excess slashes: / So for example, all of these: /this/that/ /this/that this/that/ this/that ... become: this/that There is also the chance of more than one slash occurring inside the desired text: /this/that/this/that/ So that would also need to be accounted for. The above example should become: this/that/this/that I think I need to use preg_replace() for this, but, as ever, regular expressions completely throw me. If I'm not mistaken, #^/*# should get me the first slash of the string, and more if there are more. And #*/$# should get me the last slash of the string, and more if there are more. Can I test for the first and last slash in the same expression? I think I either need something between the two that says ignore what's in the middle, or and and/or statement to say replace if this occurs at the end, or at the beginning, or both. I've looked around and can't seem to find a way of connecting these in the same search. However, I'm sure that is because I'm not familiar enough with regular expressions to know what I'm looking at. How would I connect #^/*# and #*/$# into one regular expression? Thank you for your time and advice. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: strip slashes from beginning and end of string in one expression
M. Sokolewiczz, Stut, Thank you for your answers. Both are very helpful. I will use the trim() method, although it's helpful to know the regular expression for learning purposes. Unless I can find a way to make things much more complicated. Your time and advice is much appreciated. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Recommendations for PHP debuggers?
Paul, Robert, Thank you for replying and for your recomendations. While looking into PHP debuggers, I've often come across mention of simply using functions like var_dump() and print_r(). But unless I misunderstand the concept, one has to be always writing these commands into the code, see what they do, and then take them out again when you actually want the code to run as you intend it to be seen. And I don't see how you can do things like watch variables or set break points. Again, unless I don't see it, to watch a variable through many steps of a script, you'd have to place a var_dump() at each juncture, run the whole script, and pick through the output afterwards. If you have arrays which many elements - $_SERVER usually has about 30 or more - that could be quite a lot of text dumped to the screen. While I can see that this approach would work, it also seems to me to involve much more manual labour. In the end, it may just be a personal thing. I'm much more of a graphics guy who wants to do some more stuff with his web pages than a hard core coder. I prefer a more GUI approach to development. Zend didn't really wow me. It took weeks of back and forth with their support to finally get it up to speed. I'll give them credit for having very friendly and responsive support staff. But I would have much rather not needed to use their support so much. But I'd rather that then have to have to build my own set of error handlers, which would themselves need constant tweaking, especially as I'm a newbie. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Recommendations for PHP debuggers?
PHP List, For the last month I have been using Zend Studio and Zend Platform on the one month trial period. It works well enough that I was considering purchasing it. But it's only now that I realize that the one feature that makes it worthwhile for me, the debug server option, is only available in the professional edition. I'm just a lone PHP programmer doing web pages for mainly non-profit (not charitable, just extremely cash poor) organizations. The difference between the 100 US dollar standard edition and the 300 US dollar professional edition is a deal breaker. So I'm looking around for other debugging options. The best contender so far has been Quanta with the Gubed plug in. But it is buggy, and while I've had success in running it, I've also had as much trouble. Especially with some error messages that won't go away: http://forum.gubed.mccabe.nu/viewtopic.php?t=396sid=5b76626496aab99293e062c494a7af2e After that PHPeclipse seems good. By seems I mean that I've installed Eclipse and PHPeclipse and can run them and see they have a sexy interface and all. But trying to download the DBG package that makes PHPeclipse interface with the server is near impossible. As I'm an Ubuntu user, I tried looking up distro-specific instructions for installing DBG, and the one forum entry on the topic I found: http://www.ubuntuforums.org/showthread.php?t=6672 ... says to go to this web page: http://www.phpeclipse.de/tiki-index.php?page=DbgBasedDebugger ... where the installation instructions are for Windows! There's also a package called NuSphere, which is paid software, but also rests on the DBG debugger technology. I'm very hesitant to encounter the same difficulties in installing DBG and having to pay for it as well. I asked once before on this list about which PHP editors people recommend, which is how I heard of Eclipse. However, now I'm asking: Does anyone know how to get a reliable PHP graphical debugger to actually install and work on Linux? Any tutorials or instructions available anywhere that are newbie friendly? After all, aren't the newbies the ones most likely to be the ones to use a GUI debugger? Any advice or help would be greatly appreciated. Thank you for your time. -- Dave M G Ubuntu 6.06 LTS Kernel 2.6.17.7 Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Creating User Friendly URLS [SOLVED]
PHP List, Thank you to everyone who helped out. I'm happy to report that the issue is solved, mainly with the help of my local LUG. I am getting nice friendly URLs, so mod_rewrite seems to be working. The solution was almost entirely to do with getting Apache working. Once I had the URLs correctly pointing to my index.php file, then manipulating $_SERVER['REQUEST_URI'] was a snap. The trickiest part for me was that on my own Apache server, mod_rewrite was not enabled. In any case, for my own reference as well as others, although the path to the answer was a little stumbly, here are the steps that I think ultimately lead to getting everything to work. This is entirely to do with setting up Apache to handle friendly URLS, but hopefully will be of use to PHP developers. 1. # sudo a2enmod rewrite 2. Confirm that the rewrite.load file is in /etc/apache2/mods-enabled Currently I have the following files in that directory: cgi.load php5.conf php5.load rewrite.load 3. # sudo gedit /etc/apache2/sites-available/default Find where it says: Directory /var/www/ Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all And change AllowOverride None to AllowOverride all. (I noticed that None was in upper case, and all was lowercase. Don't know if case is important, but this is the way that it worked for me). Some sites said to edit /etc/apache2/sites-enabled/000-default, or sometimes default-000, but they are just symlinks to /etc/apache2/sites-available/default (at least in my case). 4. # sudo gedit /etc/apache2/httpd.conf Add the following lines: IfModule mod_rewrite.c RewriteEngine On /IfModule No other editing of httpd.conf was necessary, despite some sites that said to use LoadModule. It should be noted, though, that even though mod-rewrite is working, it isn't listed when I run /usr/sbin/apache2 -l. I don't know if that's odd behaviour or not, just that it seemed like it was supposed to be listed there. 5. Reload the apache modules and restart Apache. # sudo /etc/init.d/apache2 force-reload # sudo /etc/init.d/apache2 restart 6. Create an .htaccess file (if there isn't one already) in the directory where one wants to create user friendly URLS, and add the following: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php These rules say that if the file or directory named in the URL is real, then go there. Otherwise, go to the index file for processing. At least that's what it seems to do. I didn't write it, so I can't assure anyone of the correctness of the syntax. It should be noted, though, that even though mod-rewrite is working, it isn't listed when I run /usr/sbin/apache2 -l. I don't know if that's odd behaviour or not, just that it seemed like it was supposed to be listed there. If anyone can see problems in the above, or if I've misunderstood some part, please let me know. Thanks to the PHP list for their ever-present help and support. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Creating User Friendly URLS
PHP List, My goal is to create user and search engine friendly URLs like: mysite.com/my_web_page_title Instead of: mysite.com/index.php?pageID=1 I asked about this before: http://marc.theaimsgroup.com/?l=php-generalm=113597988027012w=2 And there is this helpful tutorial: http://agachi.name/weblog/archives/2005/01/30/rewriting-dynamic-urls-into-friendly-urls.htm Both of which refer to a variable called $_SERVER['PATH_INFO']. But, in the php.net manual, in the predefined variables page, 'PATH_INFO' is only obliquely referenced in the $_SERVER variable description, under the 'PATH_TRANSLATED' element. When I've tried echoing out the contents of $_SERVER['PATH_INFO'], I get nothing. I'm trying to set it so that pages are named according to their title in my MySQL database. So my script will pull my_web_page_title out of the URL, match that against the database, and then display the appropriate contents. I thought I could do this by simply making my link into: a href=index.php/my_web_page_titleMy Web Page Title/a And then stripping out the index.php, and using the remainder for both the URL and the database lookup. But, while I'm sure there are more steps than that, I'm halted initially because I'm not sure where in the $_SERVER array my URL is being stored. Any advice on how to proceed here would be greatly appreciated. Thank you. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dividing, and keeping, text from the first space
PHP List, This regular expression stuff is way tricky. Thanks to help from this list, I have an expression that will select the first word of a string, up to the first white space: #^(.*)\s#iU But after some consideration, I realized that I wanted to keep both parts of the original text. The first word, and then everything that came after it, should be divided and stored in separate variables. I looked through the php.net manual, and found preg_split(). At first I thought using my original expression would work, if I included the PREG_SPLIT_DELIM_CAPTURE parameter. It would pull out the first word, but also keep it. Turns out that's not true. It removes the first word and the space, and looks for something before and after and only finds something after. Thus, in my current situation, it returns only one variable, which contains everything after the first space. I realized what I need to do in this case is not select everything up to the first space, but to find the first space without selecting what comes before it. So the expression I had wasn't suitable for preg_split(). So then, what is the right expression? Looking back over previous discussion and resources about regular expression syntax, I thought I had to say: Start at the beginning: ^ Ignore anything that isn't a space: [^\s] Select the space character: \s Be case insensitive and not greedy: iU Thus, my expression should be (using hash marks, #, as delimiters): #^[^\s]|s#iU More specifically, my preg_split() syntax is: $parts = preg_split(#^[^\s]|s#iU, $word, PREG_SPLIT_DELIM_CAPTURE); But it returns a two element array, where the first element is empty, and the second element is the whole original string. Where did I go wrong this time? Thank you for all your time and help. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dividing, and keeping, text from the first space
Robert, Thank you for your quick response and helpful advice. Use preg_match() and pay special attention to the manual as it refers to the third parameter :) The expression you need follows: #^([^\\s]*)\\s(.*)$#U This works perfectly. I now see that the preg_match() function returns an array with the original text, the selected text, and the discarded text. That wasn't clear to me before when I wasn't looking for that kind of behavior. But now that you point it out I see how it works. But I am still confused about the expression you used. I can't quite break it down: The opening ^ says to start at the beginning of the line. The brackets indicate a sub-expression. The square brackets indicate a character class (?). The ^ inside the square brackets means not. First question, why is there an extra backslash before the space marker \s? Isn't that an escape character, so wouldn't that turn the following space marker into a literal backslash followed by an s? The * says to select everything matching the preceeding conditions. There's that double backslash and s again. Hmm... does the (.*) after the second \s mean to match all the whitespace found? For example if there happened to be two space characters instead of just one? The PHP manual says the $ means to assert end of subject. Which I think means stop looking for any more matches. So basically I'm confused about the extra escape slashes. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Create an EUC-JP encoded file just for download, not to be kept on server
PHP List, In the last stage of my current script, I need to take a bunch of data from the database and put it into a text file for the user to save to their computer and import into an application. The file being created is just a list of Japanese words and definitions delineated by tabs. The file format should be a text file. Actually, it could also be CSV file, since it's tab delineated data. The application being imported to only accepts EUC-JP encoding for text files that include Japanese text, so my data, which is stored in the database as UTF-8, will need to be converted to EUC-JP at some point along the way to being written to the file. This file need not ever be stored on the server. In fact, I'd rather it not so as to avoid any headaches with permissions settings (which always give me a headache, but that's a rant for another day). So, I'm looking on php.net for functions that would be able to create a file out of some data and pass it along to the user. But it seems that the assumption of all the file functions (that I've found) such as fwrite(), fopen(), file(), readfile(), and others are all about taking an existing file and working with it. And more importantly, all of them seem to assume that the place where the file would be stored is on the servers system, and not immediately passed on to the user. I have a suspicion that this is one of those situations where the starting point is assumed to be so simple that no one goes out of their way to document or explain it. I'm too lost to know where to begin. How do I create a file that the user saves, and is not stored on the server? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Create an EUC-JP encoded file just for download, not to be kept on server
Robert, Ray, Richard, Thank you all for responding with helpful advice. Robert said: It's all about the headers... header( Content-type: text/csv ); header( Content-disposition: inline; filename=$filename ); Ah... that's something I think I never would have figured out with the manual alone. Now that I know, it seems super easy. Thanks to everyone - those who responded directly as well as the PHP list in general. With the right regular expressions and file handling mechanisms in place, I now have a script that does everything I set out for it to do. Everyone's time and expertise is very much appreciated. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dividing, and keeping, text from the first space
Robert, Thank you for responding. The extra slashes are to properly escape the backslash character since you are using double quotes As I said you may want the following pattern in cases where no space exists: '#^([^\s]*)\s?(.*)$#' Thank you for your detailed explanation. Especially with regards to the impact of double quotes versus single quotes in an expression. I see now that I most likely will find it simpler to use single quotes and avoid having to escape characters excessively. As you might have seen in a response of mine to another of your postings, all this advice has come together, and my script now accomplishes what I had hoped it would. Thank you and the PHP list in general for the continued great support. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular expression to find from start of string to first space
PHP, Shouldn't this regular expression select everything from the start of the string to the first space character: $firstWord = preg_match('#^*(.*) #iU', $word); It doesn't, so clearly I'm wrong, but here's why I thought it would: The enclosing has marks, #, I *think* just encloses the expression. I was told to use them before, but I can't find them here: http://jp2.php.net/manual/en/reference.pcre.pattern.syntax.php The caret, ^, says to start at the beginning of the line. The first asterix, * after the caret says to use any starting character. The space just before the second # is the closing character of my search. The (.*) in the middle says to take anything in between the beginning of the line and the space. iU says, be case insensitive, and don't be greedy. So, it should start at the beginning of the line and get everything up to the first space. But it doesn't work. Where did I go wrong? -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using preg_match to find Japanese text
Richard, Madoka, Thank you for your insights into searching for Japanese characters. I've decided to stick with searching for words as determined by the placement of spaces within the source text. Thank you for your time and advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression to find from start of string to first space [SOLVED]
Richard, Adam, Barry, Dave, David, Thank you all for your helpful advice regarding expressions. I was able to combine all your advice, and made some additional discoveries along the way. The winning expression is: #^(.*)\s#iU First, I discovered that sometimes the source text had an unexpected space character at the very beginning. So I realized that I needed to do trim() to ensure proper functionality of the expression. Next, it seems it's better to use \s than an actual space, . It might be the case that both are okay, but I've had success with \s, so I decided to stop experimenting. I tried, as Adam suggested, to use substr() instead of a regular expression. The syntax he provided may work as far as finding the right text to extract. But I can't be sure because it seems to have problems with the character encoding. The word being extracted is in UTF-8 encoded Japanese. The regular expression seems to input and output it fine. But I couldn't find a way of using the substr() function without the text coming out as ASCII gibberish. So I'm calling this one solved for me, as I have working code. Although if anyone believes that it could be more efficient or something, of course I'm all ears. Thank you for all your time and advice. -- Dave M G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php