Re: [PHP] wildcard search?
That's because this is a MySQL-specific question and you should be reading the MySQL documentation or asking on the MySQL list. -Rasmus On Mon, 11 Nov 2002, Håkan wrote: I'm trying to make a small and simple search function, but it only works for exact searches, and I can't figure out how to make a wildcard search, if I do it in the php or in the mysql_query, can't really find anything about it and I don't know what to look for on php.net Håkan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] wildcard search?
You'll do it in the database, not PHP. Look into using LIKE in your query... SELECT * FROM yourtable WHERE column LIKE '%searchterm%' The % characters are wildcards that'll match any amount of characters. You can use _ to match a single character. You could also look at FULL-TEXT indexing in MySQL to create a better search feature. ---John Holmes... -Original Message- From: Håkan [mailto:hw2k;barrysworld.com] Sent: Monday, November 11, 2002 4:43 PM To: [EMAIL PROTECTED] Subject: [PHP] wildcard search? I'm trying to make a small and simple search function, but it only works for exact searches, and I can't figure out how to make a wildcard search, if I do it in the php or in the mysql_query, can't really find anything about it and I don't know what to look for on php.net Håkan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] wildcard search?
RTFM... http://www.mysql.com/doc/en/Pattern_matching.html Håkan wrote: I'm trying to make a small and simple search function, but it only works for exact searches, and I can't figure out how to make a wildcard search, if I do it in the php or in the mysql_query, can't really find anything about it and I don't know what to look for on php.net Håkan -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wildcard search
How about: $a = explode (' ', shell_exec (ls $foldername/*.html)); This should return an array that contains the name of all the *.html files in the folder $foldername, if any. Hope this helps. Cheers, Marco - php|architect -- The Monthly Magazine For PHP Professionals Come visit us on the web at http://www.phparch.com! On Fri, 2002-11-08 at 09:34, Mako Shark wrote: I've tried doing a search for this problem on the web, but haven't found anything, nor have I found any solution on the php.net documentation. Does anyone know if it's possible to do a file search with a wildcard character? I need to find if there are any HTML files in a certain directory, but file_exists(htmls/*.html) doesn't seem to work when tested. Neither do similar applications of readdir(). Is there another way to do this, or do I have to do a readdir() and read the filename of every file until I find an HTML or until all files have been read. - Do you Yahoo!? U2 on LAUNCH - Exclusive medley videos from Greatest Hits CD -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Wildcard search
-Original Message- From: Mako Shark [mailto:phpman2000;yahoo.com] do I have to do a readdir() and read the filename of every file until I find an HTML or until all files have been read. This is what the shell expression supplied by Marco Tabini actually does; doing it in PHP (readdir(), etc.) eliminates the exec of the shell process and is faster (readdir() is a thin veneer on the readdir system call) and the problem of portability if you want to use this on both Unix and Windows. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wildcard search
$a = explode (' ', shell_exec (ls $foldername/*.html)); Didn't know of shell_exec() until now. It works, though. Thanks! Is there any reason why it wouldn't work? If I changed servers, say, and there were some ports blocked and etc. etc., is there a risk that I should know? - Do you Yahoo!? U2 on LAUNCH - Exclusive medley videos from Greatest Hits CD
Re: [PHP] Wildcard search
Well, as a general rule, it won't work if you're not using a UNIX o/s or if PHP has been set up with safe mode on, or if you don't have the right permission to see that folder. That's probably a non-inclusive list, but there should be ways around each of these problems (depending on the degree of control you have over the server). Marco - php|architect -- The Monthly Magazine For PHP Professionals Come visit us on the web at http://www.phparch.com! On Fri, 2002-11-08 at 11:14, Mako Shark wrote: $a = explode (' ', shell_exec (ls $foldername/*.html)); Didn't know of shell_exec() until now. It works, though. Thanks! Is there any reason why it wouldn't work? If I changed servers, say, and there were some ports blocked and etc. etc., is there a risk that I should know? - Do you Yahoo!? U2 on LAUNCH - Exclusive medley videos from Greatest Hits CD -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wildcard search
Mako Shark wrote... Didn't know of shell_exec() until now. It works, though. Thanks! Is there any reason why it wouldn't work? If I changed servers, say, and there were some ports blocked and etc. etc., is there a risk that I should know? My understanding is that many security-conscious providers don't allow shell_exec(). Mine doesn't. -- Charles Wiltgen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wildcard search
Well, as a general rule, it won't work if you're not using a UNIX o/s orif PHP has been set up with safe mode on, or if you don't have the rightpermission to see that folder. That's probably a non-inclusive list, butthere should be ways around each of these problems (depending on thedegree of control you have over the server). These are fine. I'm not going to use Windows for a server. Won't the same problem in relation to directory permissions stop me even if I just did a simple readdir()? The only one I'm too worried about is the safe mode thing. It works for now, though. The next server I'm moving to will hopefully be my own, so I'll have complete control. And, if not, all of my shell_execs() are in a function, so I only have to change it in one place. But is it less troublesome to use a popen instead of shell_exec? What are the differences, aside from that popen remains open past one command? I'm using both here and there in my site, and am wondering if one is better than the other if all my shell commands are single-line commands. __ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 ---BeginMessage--- Well, as a general rule, it won't work if you're not using a UNIX o/s orif PHP has been set up with safe mode on, or if you don't have the rightpermission to see that folder. That's probably a non-inclusive list, butthere should be ways around each of these problems (depending on thedegree of control you have over the server). These are fine. I'm not going to use Windows for a server. Won't the same problem in relation to directory permissions stop me even if I just did a simple readdir()? The only one I'm too worried about is the safe mode thing. It works for now, though. The next server I'm moving to will hopefully be my own, so I'll have complete control. And, if not, all of my shell_execs() are in a function, so I only have to change it in one place. But is it less troublesome to use a popen instead of shell_exec? What are the differences, aside from that popen remains open past one command? I'm using both here and there in my site, and am wondering if one is better than the other if all my shell commands are single-line commands. __ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 ---End Message--- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wildcard search
If you're only executing one-liners and get all the results back you're better off using shell_exec(). popen() lets you open a pipe to a command--that way, you can funnel data to it as if you were typing from the keyboard. Permissions would be a problem with readdir() as well. Marco -- php|architect - The magazine for PHP Professionals The first monthly worldwide magazine dedicated to PHP programmer Come visit us at http://www.phparch.com! ---BeginMessage--- Well, as a general rule, it won't work if you're not using a UNIX o/s orif PHP has been set up with safe mode on, or if you don't have the rightpermission to see that folder. That's probably a non-inclusive list, butthere should be ways around each of these problems (depending on thedegree of control you have over the server). These are fine. I'm not going to use Windows for a server. Won't the same problem in relation to directory permissions stop me even if I just did a simple readdir()? The only one I'm too worried about is the safe mode thing. It works for now, though. The next server I'm moving to will hopefully be my own, so I'll have complete control. And, if not, all of my shell_execs() are in a function, so I only have to change it in one place. But is it less troublesome to use a popen instead of shell_exec? What are the differences, aside from that popen remains open past one command? I'm using both here and there in my site, and am wondering if one is better than the other if all my shell commands are single-line commands. __ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 ---BeginMessage--- Well, as a general rule, it won't work if you're not using a UNIX o/s orif PHP has been set up with safe mode on, or if you don't have the rightpermission to see that folder. That's probably a non-inclusive list, butthere should be ways around each of these problems (depending on thedegree of control you have over the server). These are fine. I'm not going to use Windows for a server. Won't the same problem in relation to directory permissions stop me even if I just did a simple readdir()? The only one I'm too worried about is the safe mode thing. It works for now, though. The next server I'm moving to will hopefully be my own, so I'll have complete control. And, if not, all of my shell_execs() are in a function, so I only have to change it in one place. But is it less troublesome to use a popen instead of shell_exec? What are the differences, aside from that popen remains open past one command? I'm using both here and there in my site, and am wondering if one is better than the other if all my shell commands are single-line commands. __ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 ---End Message--- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Wildcard search
If you're only executing one-liners and get all the results back you're better off using shell_exec(). popen() lets you open a pipe to a command--that way, you can funnel data to it as if you were typing from the keyboard. That's what I'll do then: use shell_exec(). Permissions would be a problem with readdir() as well. So this really shouldn't be a deciding factor then. Anyway, I've got it working out. I have it returning an array of filenames if successful. If it's a successful call, but no files exists (for instance *.html with no HTML files), then it returns 0. If it can't read the directory or the dir doesn't exist, it returns NULL. Just to make sure, I can do this: if($files = GetFileListing(htmls\*.html)) { . . . } and it will skip it if there either are no HTML files, oe htmls doesn't exist, right? If I get a 0 or a NULL return? (I figure, if I need to distinguish between these two, I can always do a $==0 or $==NULL comparison). __ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php