[PHP] Re: parsing out quoted text
On Fri, 09 Jun 2006 14:53:09 +0200, sam [EMAIL PROTECTED] wrote: $str='bass electric organ bagpipes'; $parser($str); $query=SELECT * FROM table WHERE tb_instr = bass AND tb_instr = electric organ //quoted phrase AND tb_instr = bagpipes; Anybody know where I can just copy code that will do the above? thanks I once for just the fun of it, made a regular expression to solve this kind of problem. I haven't tried it in production enviroment, but only on some basic examples. It should support both single and double quotes. $str = 'bass electric organ bagpipes'; preg_match_all(/(?=('|\))[^\\1]+(?=\\1)|[^ \']+/,$str,$match); /* $match[0] Array ( [0] = bass [1] = electric organ [2] = bagpipes ) */ foreach($match[0] as $key = $value) { $match[0][$key] = 'tb_instr = '.mysql_escape_string($value).''; } $sql = SELECT * FROM table WHERE .implode(' AND ',$match[0]); print($sql); //SELECT * FROM table WHERE tb_instr = bass AND //tb_instr = electric organ AND tb_instr = bagpipes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: replace special characters
On Thu, 24 Feb 2005 09:14:32 +0100, Frank Arensmeier [EMAIL PROTECTED] wrote: Hello everybody! I was wondering if you could help me with a little problem I ran into some days ago. In my database I have some information about file paths. Originally, those paths come from a Windows Excel spreadsheet and look like ..\1 PDF Filer\65051.PDF. In my PHP code I try to do two things: 1) replace .. with a string like file://server/folder 2) replace all \ characters with /. The PHP code looks something like: $path_to_file = ..\1 PDF Filer\65051.PDF; $things_to_look_for = array(.., \); $things_to_replace_with = array(file://server/folder, /); $link = str_replace($things_to_look_for, $things_to_replace_with, $path_to_file); The big problem is the character \ which, if I got it right, in UNICODE is used for things like expressing line breaks ('\n' or something like this). The code above is resulting in the following error massage: Parse error: parse error, expecting `')'' in /xxx/xxx/xxx/TMPz06yoces6o.php on line 2. Is there a simple solution for this problem? Regards, Frank You are escaping the last quote, meaning that the rest of your code is quoted. What you need to do is to escape the escape character. $path_to_file = addslashes(..\1 PDF Filer\65051.PDF); $things_to_look_for = array(.., \\); You should use addslashes() or similar on you're path name, as some escaped characters have certain meanings. \n for example means a new line character, while \\n on the other hand means \ followed by n. Manual: http://www.php.net/types.string -- Stian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: pdf properties
On Thu, 10 Feb 2005 12:28:19 -0700, Jason Motes [EMAIL PROTECTED] wrote: Hello, Is there anyway to retrieve the properties from a pdf file using php? When you right click on a pdf file in windows you can see the title of the file and you can change this property there also. I wrote a php page that lists all files in a certain directory. I want to be able show the actual title of the document instead of just the file name. I have searched the manual and google, everything that comes up refers to generating pdfs on the fly, not working with an already made pdf. Thanks in Advance, Jason Motes If you study the structure of pdf in a text editor, you'll notice that it is quite readable. If you go to the end of a document, prefferably a small one, you will see the trailer. Here is al list of all bytepositions of the objects the pdf document contains. These objects can be images, text, page descriptions, page groups and so on. There can also be a reference to the properties of the document wich can contain creator, author, title etc. It is easy to read the objects, but to change them can prove rather difficult, as you will need to update the trailer informaition with new byteposition for all objects that comes after the properties (hard to explain), unless you keep the new info the same length. But as you only need to extract the title you can do this with a simple regexp. while(filelistingstuff) { $document = file_get_contents($pdf); if(preg_match(/\/Title\s\((.*?)\)/i,$document,$match)) { $title = $match[1]; } else { $title = $filename; } } Hope this helps. -- Stian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: AW: [PHP] regular expresion
Hi! strip_tags() would not solve his problem, although that was my first thought as well. To skip tags, including content, where content contains certain words is possible. But to me the problem occurs with nested tags. What do you want to do when you meet tables? Here is an example that solves you're example, and similar situations, but not much else. preg_match_all(/(?!body|script|etc)(\w+)[^]*((?(?!eee|etc|\/ \\1).)*)\/\\1/s,$text,$match); print_r($match[2]); will return [0] = aaa [1] = aaa hhh [2] = aaa (?!body|script|etc) is used to filter unwanted tags, and in (?!eee|etc|\/\\1) you can put your filter words. Hope this helps you anyway. -- Stian On Wed, 2 Feb 2005 11:36:26 +0100, Mirco Blitz [EMAIL PROTECTED] wrote: Hi, Use strip_tags() instead of regex. http://www.php-center.de/en-html-manual/function.strip-tags.html Greetings Mirco -Ursprüngliche Nachricht- Von: php [mailto:[EMAIL PROTECTED] Gesendet: Mittwoch, 2. Februar 2005 09:25 An: php-general@lists.php.net Betreff: [PHP] regular expresion I want to parse a html file for instance body paaa /p baaa hhh /b paaa eee /p iaaa /i /body and I want to create a regular expresion wich is able to extract entire text from enclosed tags WITHOUT a particular word for example eee final I want to obtain this result aaa aaa hhh aaa Any solution? thank you Silviu -- 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
[PHP] Re: Regex help
On Fri, 28 Jan 2005 14:59:29 -0700, [EMAIL PROTECTED] wrote: OK, this is off-topic like every other regex help post, but I know some of you enjoy these puzzles :) I need a validation regex that will pass a string. The string can be no longer than some maximum length, and it can contain any characters except two consecutive ampersands () anywhere in the string. I'm stumped - ideas? TIA Kirk if(preg_match(/^([^]|(?!)){1,42}$/,$string)) { This one will work I think. Returns false if it finds two consecutive or exceeds 42 chars. -- Stian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php