Re: [PHP] Stripping carriage returns
On Tue, 2011-01-11 at 11:13 -0800, Richard S. Crawford wrote: I'm retrieving CLOB data from an Oracle database, and cleaning up the HTML in it. I'm using the following commands: $content = strip_tags($description-fields['CONTENT'],'polulli'); $content = preg_replace(/p.*/,p,$content); The second line is necessary because the p tag frequently comes with class or style descriptions that must be eliminated. This works on the whole except where the p tag with the style definition is broken up over two or more lines. In other words, something like: p class = bullettext style = line-height: normal border: 3; In this case, the second line of my code does not strip the class or style definitions from the paragraph tag. I've tried: $content = nl2br($content) and $content = str_replace(chr(13),$content) and $content = preg_replace(/[.chr(10).|.chr(13).]/,,$content) (I've read that Oracle uses chr(10) or chr(13) to represent line breaks internally, so I decided to give those a try as well.) and $content = str_replace(array('\n','\r','\r\n'),$content) all to no avail; these all leave the line break intact, which means my preg_replace('/p.*/','p',$content) line still breaks. Anyone have any ideas? If you don't have too many problems with the HTML code (like broken tags, etc) then maybe you could use strip_tags() which will perform better than a regex in this instance, and should work with tags over multiple lines as well (although I can't say I've specifically tried that) Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Stripping carriage returns
On Tue, Jan 11, 2011 at 14:13, Richard S. Crawford rich...@underpope.com wrote: $content = str_replace(chr(13),$content) and $content = str_replace(array('\n','\r','\r\n'),$content) Neither of these have replacement values, which might just be a typo. However, the larger issue is in the single (literal) quotes in the second example. Change that to: $content = str_replace(array(\n,\r,\r\n),'',$content); If you're ambitious, you can try the FileConv PHP extension available here: http://links.parasane.net/dxdv -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping carriage returns
On Tue, Jan 11, 2011 at 11:13 AM, Richard S. Crawford rich...@underpope.com wrote: $content = preg_replace(/[.chr(10).|.chr(13).]/,,$content) This should be $content = preg_replace('/[\r\n]/','',$content) First, you can embed \r and \n directly in the regular expression as-is (not converted to chr(10) by PHP) by using single quotes. Second, you don't want the vertical bar inside []. That's only for (). David
Re: [PHP] Stripping carriage returns
Strangely, when I use \n, or nl2br(), or PHP_EOL, or anything like that, it strips out not just line breaks, but most of the rest of the text as well. I suspect an encoding issue at this point. Daniel, you were right when you said that neither of my str_replace lines had repl.acement values; that was indeed a typo when I was copying the code over into my email. Ashley, I've already been using strip_tags to eliminate all but p, ol, ul, and li tags. On Tue, Jan 11, 2011 at 11:24 AM, David Harkness davi...@highgearmedia.comwrote: On Tue, Jan 11, 2011 at 11:13 AM, Richard S. Crawford rich...@underpope.com wrote: $content = preg_replace(/[.chr(10).|.chr(13).]/,,$content) This should be $content = preg_replace('/[\r\n]/','',$content) First, you can embed \r and \n directly in the regular expression as-is (not converted to chr(10) by PHP) by using single quotes. Second, you don't want the vertical bar inside []. That's only for (). David -- Sláinte, Richard S. Crawford (rich...@underpope.com) http://www.underpope.com
Re: [PHP] Stripping carriage returns
On Jan 11, 2011, at 11:34 AM, Richard S. Crawford wrote: Strangely, when I use \n, or nl2br(), or PHP_EOL, or anything like that, it strips out not just line breaks, but most of the rest of the text as well. I suspect an encoding issue at this point. Daniel, you were right when you said that neither of my str_replace lines had repl.acement values; that was indeed a typo when I was copying the code over into my email. Ashley, I've already been using strip_tags to eliminate all but p, ol, ul, and li tags. Perhaps you could use tidy to clean up the formatting (use -wrap 0) before attempting to strip out the stuff you want to get rid of. Mari -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping carriage returns
On 1/11/2011 11:13 AM, Richard S. Crawford wrote: I'm retrieving CLOB data from an Oracle database, and cleaning up the HTML in it. I'm using the following commands: $content = strip_tags($description-fields['CONTENT'],'polulli'); $content = preg_replace(/p.*/,p,$content); The second line is necessary because the p tag frequently comes with class or style descriptions that must be eliminated. This works on the whole except where the p tag with the style definition is broken up over two or more lines. In other words, something like: p class = bullettext style = line-height: normal border: 3; In this case, the second line of my code does not strip the class or style definitions from the paragraph tag. I've tried: $content = nl2br($content) and $content = str_replace(chr(13),$content) and $content = preg_replace(/[.chr(10).|.chr(13).]/,,$content) (I've read that Oracle uses chr(10) or chr(13) to represent line breaks internally, so I decided to give those a try as well.) and $content = str_replace(array('\n','\r','\r\n'),$content) all to no avail; these all leave the line break intact, which means my preg_replace('/p.*/','p',$content) line still breaks. Anyone have any ideas? Richard, Looks like you need to read up on the modifiers for preg_* functions. Start here: http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php I would change your second line regex to the following. $content = preg_replace(/p.*/is, p, $content); The modifiers after the second / are i = case-insensitive s = include new lines in your '.' character match. New lines are excluded by default. Can't remember right now, nor do I have the time to test, you might need to invert the greediness of the match using a 'U' after the second / also. So... $content = preg_replace(/p.*/isU, p, $content); YMMV Let us know how this works out for you. Jim Lucas PS: you might want to swap the order of these two statements. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping Characters
On 23 June 2010 01:03, Rick Dwyer rpdw...@earthlink.net wrote: $find = '/[^a-z0-9]/i'; Replace that with ... $find = '/[^a-z0-9]++/i'; And now you only need ... $new_string = trim(preg_replace($find, $replace, $old_string)); -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping Characters
Hello, can this resolve your problem? $trans = array( from = to, another = to); $moditem = StrTr($moditem, $trans); -- http://cz.php.net/manual/en/function.strtr.php David -Original Message- From: Rick Dwyer [mailto:rpdw...@earthlink.net] Sent: Tuesday, June 22, 2010 5:41 PM To: php-general@lists.php.net Subject: [PHP] Stripping Characters Hello List. I need to remove characters from a string and replace them with and underscore. So instead of having something like: $moditem = str_replace(--,_,$mystring); $moditem = str_replace(?,_,$mystring); $moditem = str_replace(!,_,$mystring); etc. For every possible character I can think of, is there a way to simply omit any character that is not an alpha character and not a number value from 0 to 9? --Rick -- 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] Stripping Characters
On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote: Hello List. I need to remove characters from a string and replace them with and underscore. So instead of having something like: $moditem = str_replace(--,_,$mystring); $moditem = str_replace(?,_,$mystring); $moditem = str_replace(!,_,$mystring); etc. For every possible character I can think of, is there a way to simply omit any character that is not an alpha character and not a number value from 0 to 9? --Rick Use preg_replace(), which allows you to use a regex to specify what you want to match: $find = '/[^a-z0-9]/i'; $replace = '_'; $new_string = preg_replace($find, $replace, $old_string); Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Stripping Characters
Perhaps, ereg_replace(your regex, replacement_string, String $variable). Regards, Shreyas On Tue, Jun 22, 2010 at 9:10 PM, Rick Dwyer rpdw...@earthlink.net wrote: Hello List. I need to remove characters from a string and replace them with and underscore. So instead of having something like: $moditem = str_replace(--,_,$mystring); $moditem = str_replace(?,_,$mystring); $moditem = str_replace(!,_,$mystring); etc. For every possible character I can think of, is there a way to simply omit any character that is not an alpha character and not a number value from 0 to 9? --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shreyas Agasthya
Re: [PHP] Stripping Characters
On 22 June 2010 16:44, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote: Hello List. I need to remove characters from a string and replace them with and underscore. So instead of having something like: $moditem = str_replace(--,_,$mystring); $moditem = str_replace(?,_,$mystring); $moditem = str_replace(!,_,$mystring); etc. For every possible character I can think of, is there a way to simply omit any character that is not an alpha character and not a number value from 0 to 9? --Rick Use preg_replace(), which allows you to use a regex to specify what you want to match: $find = '/[^a-z0-9]/i'; $replace = '_'; $new_string = preg_replace($find, $replace, $old_string); Thanks, Ash http://www.ashleysheridan.co.uk Watch out for white space in there. Tabs, spaces, new lines, etc. will also be converted to underscore. $find = '/[^\w\s]/i'; [^\w\s] Match a single character NOT present in the list below «[^\w\s]» A word character (letters, digits, and underscores) «\w» A whitespace character (spaces, tabs, and line breaks) «\s» A word character is any letter or digit or the underscore character, that is, any character which can be part of a Perl word. The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place. For example, in the fr (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w. -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping Characters
On Tue, Jun 22, 2010 at 9:40 AM, Rick Dwyer rpdw...@earthlink.net wrote: Hello List. I need to remove characters from a string and replace them with and underscore. So instead of having something like: $moditem = str_replace(--,_,$mystring); $moditem = str_replace(?,_,$mystring); $moditem = str_replace(!,_,$mystring); etc. For every possible character I can think of, is there a way to simply omit any character that is not an alpha character and not a number value from 0 to 9? check the docs, the first parameter may be an array of multiple needles, e.g. $moditem = str_replace(array('-', '?', '!'), '_', $mystring); you could likely do something more elegant w/ preg_replace() tho. -nathan
Re: [PHP] Stripping Characters
Then, when does one use ereg_replace as against preg_replace? I read from one the forums that preg_* is faster and ereg_* is if not faster but simpler. Is that it? Regards, Shreyas On Tue, Jun 22, 2010 at 9:58 PM, Richard Quadling rquadl...@gmail.comwrote: A word character is any letter or digit or the underscore character, that is, any character which can be part of a Perl word. The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place. For example, in the fr (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w. The above becomes ... _A _word_ character is any letter or digit or the underscore character_ that is_ any character which can be part of a Perl _word__ The definition of letters and digits is controlled by PCRE_s character tables_ and may vary if locale_specific matching is taking place_ For example_ in the _fr_ _French_ locale_ some character codes greater than 128 are used for accented letters_ and these are matched by _w__ -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shreyas Agasthya
Re: [PHP] Stripping Characters
Thanks to everyone who responded. Regarding the myriad of choices, isn't Ashley's, listed below, the one most like to guarantee the cleanest output of just letters and numbers? --Rick On Jun 22, 2010, at 11:44 AM, Ashley Sheridan wrote: On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote: Use preg_replace(), which allows you to use a regex to specify what you want to match: $find = '/[^a-z0-9]/i'; $replace = '_'; $new_string = preg_replace($find, $replace, $old_string); Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Stripping Characters
On Tue, 2010-06-22 at 13:35 -0400, Rick Dwyer wrote: Thanks to everyone who responded. Regarding the myriad of choices, isn't Ashley's, listed below, the one most like to guarantee the cleanest output of just letters and numbers? --Rick On Jun 22, 2010, at 11:44 AM, Ashley Sheridan wrote: On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote: Use preg_replace(), which allows you to use a regex to specify what you want to match: $find = '/[^a-z0-9]/i'; $replace = '_'; $new_string = preg_replace($find, $replace, $old_string); Thanks, Ash http://www.ashleysheridan.co.uk It is clean, but as Richard mentioned, it won't handle strings outside of the traditional 128 ASCII range, so accented characters and the like will be converted to an underscore. Also, spaces might become an issue. However, if you are happy that your input won't go beyond the a-z0-9 range, then it should do what you need. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Stripping Characters
Shreyas Agasthya wrote: Then, when does one use ereg_replace as against preg_replace? I read from one the forums that preg_* is faster and ereg_* is if not faster but simpler. BUT, all the ereg_* has been depricated. DO NOT USE THEM if you want your code to work in the future. :) Is that it? Regards, Shreyas On Tue, Jun 22, 2010 at 9:58 PM, Richard Quadling rquadl...@gmail.comwrote: A word character is any letter or digit or the underscore character, that is, any character which can be part of a Perl word. The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place. For example, in the fr (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w. The above becomes ... _A _word_ character is any letter or digit or the underscore character_ that is_ any character which can be part of a Perl _word__ The definition of letters and digits is controlled by PCRE_s character tables_ and may vary if locale_specific matching is taking place_ For example_ in the _fr_ _French_ locale_ some character codes greater than 128 are used for accented letters_ and these are matched by _w__ -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jim Lucas A: Maybe because some people are too annoyed by top-posting. Q: Why do I not get an answer to my question(s)? A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping Characters
Hello again list. My code for stripping characters is below. I'm hoping to get feedback as to how rock solid it will provide the desired output under any circumstance: My output must look like this (no quotes): This-is-my-string-with-lots-of-junk-characters-in-it The code with string looks like this: $old_string = 'This is my $string -- with ƒ lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®† ¥¨ˆøπ“‘ååß∂ƒ©˙∆˚¬…æ`__'; $find = '/[^a-z0-9]/i'; $replace = ' '; $new_string = preg_replace($find, $replace, $old_string); $new_string = preg_replace(/ {2,}/, -, $new_string); $new_string = preg_replace(/ {1,}/, -, $new_string); $new_string = rtrim($new_string, -); $new_string = ltrim($new_string, -); echo $new_string; Will the logic above capture and remove every non alpha numeric character and place a SINGLE hyphen between the non contiguous alpha numeric characters? Thanks for the help on this. --Rick On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote: On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote: It is clean, but as Richard mentioned, it won't handle strings outside of the traditional 128 ASCII range, so accented characters and the like will be converted to an underscore. Also, spaces might become an issue. However, if you are happy that your input won't go beyond the a- z0-9 range, then it should do what you need. No, actually I'm fairly confident characters outside the 128 range are what are causing me problems now. So I will try Richard's method. Thanks to all. --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping Characters
On Tue, 2010-06-22 at 20:03 -0400, Rick Dwyer wrote: Hello again list. My code for stripping characters is below. I'm hoping to get feedback as to how rock solid it will provide the desired output under any circumstance: My output must look like this (no quotes): This-is-my-string-with-lots-of-junk-characters-in-it The code with string looks like this: $old_string = 'This is my $string -- with ƒ lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®† ¥¨ˆøπ“‘ååß∂ƒ©˙∆˚¬…æ`__'; $find = '/[^a-z0-9]/i'; $replace = ' '; $new_string = preg_replace($find, $replace, $old_string); $new_string = preg_replace(/ {2,}/, -, $new_string); $new_string = preg_replace(/ {1,}/, -, $new_string); $new_string = rtrim($new_string, -); $new_string = ltrim($new_string, -); echo $new_string; Will the logic above capture and remove every non alpha numeric character and place a SINGLE hyphen between the non contiguous alpha numeric characters? Thanks for the help on this. --Rick On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote: On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote: It is clean, but as Richard mentioned, it won't handle strings outside of the traditional 128 ASCII range, so accented characters and the like will be converted to an underscore. Also, spaces might become an issue. However, if you are happy that your input won't go beyond the a- z0-9 range, then it should do what you need. No, actually I'm fairly confident characters outside the 128 range are what are causing me problems now. So I will try Richard's method. Thanks to all. --Rick You can remove the second line of code, as the third one is replacing what line 2 does anyway. Also, instead of a rtrim and ltrim, you can merge the two with a single call to trim, which will work on both ends of the string at once. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Stripping Characters
Very good. Thank you. --Rick On Jun 22, 2010, at 8:14 PM, Ashley Sheridan wrote: On Tue, 2010-06-22 at 20:03 -0400, Rick Dwyer wrote: Hello again list. My code for stripping characters is below. I'm hoping to get feedback as to how rock solid it will provide the desired output under any circumstance: My output must look like this (no quotes): This-is-my-string-with-lots-of-junk-characters-in-it The code with string looks like this: $old_string = 'This is my $string -- with ƒ lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®† ¥¨ˆøπ“‘ååß∂ƒ©˙∆˚¬… æ`__'; $find = '/[^a-z0-9]/i'; $replace = ' '; $new_string = preg_replace($find, $replace, $old_string); $new_string = preg_replace(/ {2,}/, -, $new_string); $new_string = preg_replace(/ {1,}/, -, $new_string); $new_string = rtrim($new_string, -); $new_string = ltrim($new_string, -); echo $new_string; Will the logic above capture and remove every non alpha numeric character and place a SINGLE hyphen between the non contiguous alpha numeric characters? Thanks for the help on this. --Rick On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote: On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote: It is clean, but as Richard mentioned, it won't handle strings outside of the traditional 128 ASCII range, so accented characters and the like will be converted to an underscore. Also, spaces might become an issue. However, if you are happy that your input won't go beyond the a- z0-9 range, then it should do what you need. No, actually I'm fairly confident characters outside the 128 range are what are causing me problems now. So I will try Richard's method. Thanks to all. --Rick You can remove the second line of code, as the third one is replacing what line 2 does anyway. Also, instead of a rtrim and ltrim, you can merge the two with a single call to trim, which will work on both ends of the string at once. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] stripping first comma off and everything after
On Fri, Jun 18, 2010 at 3:56 PM, Adam Williams adam_willi...@bellsouth.netwrote: I'm querying data and have results such as a variable named $entries[$i][dn]: CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx Basically I need to strip off the first command everything after, so that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92. I tried echo rtrim($entries[$i][dn],,); but that doesn't do anything. Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Adam (how could I not offer feedback to one with such a distinguished first name), rtrim() removes the characters contained in the second argument, it doesn't split a string using them. I would probably use strstr() if I didn't need the other sections, or, if I needed the other sections for later, I'd use explode: $your_string = 'CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx,'; echo strstr($haystack = $your_string, $needle = ',', $before_needle = true); if ($sections = explode($delimiter = ',', $string = $your_string)) echo current($sections); Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP] stripping first comma off and everything after
On Sat, Jun 19, 2010 at 3:08 AM, Adam Richardson simples...@gmail.comwrote: On Fri, Jun 18, 2010 at 3:56 PM, Adam Williams adam_willi...@bellsouth.net wrote: I'm querying data and have results such as a variable named $entries[$i][dn]: CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx Basically I need to strip off the first command everything after, so that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92. I tried echo rtrim($entries[$i][dn],,); but that doesn't do anything. Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Adam (how could I not offer feedback to one with such a distinguished first name), rtrim() removes the characters contained in the second argument, it doesn't split a string using them. I would probably use strstr() if I didn't need the other sections, or, if I needed the other sections for later, I'd use explode: $your_string = 'CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx,'; echo strstr($haystack = $your_string, $needle = ',', $before_needle = true); if ($sections = explode($delimiter = ',', $string = $your_string)) echo current($sections); Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com Whoops! I realized in the explode example I had omitted the call to count (idea being if you didn't find any comma's, maybe you need to handle those situations differently): if (count($sections = explode($delimiter = ',', $string = $your_string)) 1) echo $sections[0]; Although, if it doesn't matter, you could just do: echo current(explode(',', $your_string)); And, as mentioned above, strstr() is one simple call if you won't need the other sections: echo strstr($your_string, ',' true); Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP] stripping first comma off and everything after
On Fri, 2010-06-18 at 15:03 -0500, Adam wrote: I'm querying data and have results such as a variable named $entries[$i][dn]: CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx Basically I need to strip off the first command everything after, so that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92. I tried echo rtrim($entries[$i][dn],,); but that doesn't do anything. Any ideas? A substring() a strpos() should do the trick: substring($entries[$i]['dn'], 0, strpos($entries[$i]['dn']-1)) Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] stripping first comma off and everything after
On Sat, 2010-06-19 at 10:09 +0100, Ashley Sheridan wrote: On Fri, 2010-06-18 at 15:03 -0500, Adam wrote: I'm querying data and have results such as a variable named $entries[$i][dn]: CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx Basically I need to strip off the first command everything after, so that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92. I tried echo rtrim($entries[$i][dn],,); but that doesn't do anything. Any ideas? A substring() a strpos() should do the trick: substring($entries[$i]['dn'], 0, strpos($entries[$i]['dn']-1)) Thanks, Ash http://www.ashleysheridan.co.uk An amendment, as I read the rest of the thread and realised that I too had missed out a check for the comma: substring($entries[$i]['dn'], 0, (strpos($entries[$i]['dn']?strpos($entries[$i]['dn']-1:strlen($entries[$i]['dn'] It doesn't look pretty, but it should do the trick. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] stripping first comma off and everything after
On Sat, Jun 19, 2010 at 05:09, Ashley Sheridan a...@ashleysheridan.co.uk wrote: A substring() a strpos() should do the trick: Echo echo [sprintf()] -- /Daniel P. Brown URGENT: EXTENDED TO SATURDAY, 19 JUNE: $100 OFF YOUR FIRST MONTH, FREE CPANEL FOR LIFE ON ANY NEW DEDICATED SERVER. NO LIMIT! daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ We now offer SAME-DAY SETUP on a new line of servers! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping first comma off and everything after
On 6/19/2010 3:08 AM, Adam Richardson wrote: $before_needle = true Requires 5.3 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping first comma off and everything after
Adam Williams wrote: I'm querying data and have results such as a variable named $entries[$i][dn]: CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx Basically I need to strip off the first command everything after, so that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92. I tried echo rtrim($entries[$i][dn],,); but that doesn't do anything. Any ideas? ?php preg_replace( '#,.*$#', '', $entries[$i]['dn'] ); ? Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping first comma off and everything after
On Fri, Jun 18, 2010 at 15:56, Adam Williams adam_willi...@bellsouth.net wrote: I'm querying data and have results such as a variable named $entries[$i][dn]: CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx Basically I need to strip off the first command everything after, so that I just have it display CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92. I tried echo rtrim($entries[$i][dn],,); but that doesn't do anything. Any ideas? Check out substr() with strpos(). ?php $s = 'CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92,OU=XXf,OU=XX,OU=X,DC=,DC=xx,DC=xxx'; if (substr($s,0,strpos($s,',')) == 'CN=NTPRTPS3-LANIER-LD335c-LH107-PPRNP9A92') { echo Good..PHP_EOL; } else { echo Bad..PHP_EOL; } ? -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ We now offer SAME-DAY SETUP on a new line of servers! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
On Wed, September 20, 2006 7:13 pm, Christopher Watson wrote: I've been coding with PHP for maybe a year. So I'm somewhat new to it. But I've learned quickly, and created a fairly serious LAMP app that is capable of returning large query results. During my investigation into various means for incrementally reducing the response sizes, I've discovered output buffering with a callback function. So, as an experiment, I bracketed my includes of the Fusebox files in index.php with ob_start('sweeper') and ob_end_flush(), and placed the simple callback function at the top of the file that performs a preg_replace on the buffer to strip all excess space: function sweeper($buffer) { return preg_replace(/\s\s+/, , $buffer); } Here's where you MIGHT get bit in the butt: 1. Anything in a PRE tag is gonna suck big-time 2. Any kind of DATA from your db with multiple spaces will lose data Now, you might maybe be able to fix these by religiously always doing $output = str_replace(' ', 'nbsp', $output); on the DATA from the DB, or any kind of PRE tags stuff you use. Or maybe in YOUR application, neither of these matters. Test it with JUST the output buffer and without the whitespace crunch -- You may find that the ob is the big win, especially if you have a zillion echo statements going on. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
Cannot compression be set in .htaccess? Or even within the script??? I suspect you could even find a PHP class out there to compress and send the right headers to do it all in PHP, regardless of server settings... On Wed, September 20, 2006 7:33 pm, Christopher Watson wrote: Hi Robert, Well, I think the main reason I'm not using transparent output compression is because this app shares php.ini with several other PHP apps on the server, and I don't want to foist this change on the admins of those apps. I was trying to come up with a localized strategy for trimming my app's output. The pre/pre issue is not an issue for me. -Christopher On 9/20/06, Robert Cummings [EMAIL PROTECTED] wrote: Should be an issue as long as you're not stripping whitespace from between pre/pre tags. Although, one must wonder why you don't just use output compression since all that whitespace would just compress anyways as would all the other content. In fact 900k with fairly standard content would shrink to about 90k. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback [SOLVED]
Thanks for the follow-up Richard. I am now bracketing my Fusebox core includes with ob_start(ob_gzhandler) and ob_end_flush(). It's done wonders for those large query results. And since there is absolutely nothing in this app that relies on multiple contiguous whitespace characters, I'm good to go. Christopher Watson On 9/22/06, Richard Lynch [EMAIL PROTECTED] wrote: Cannot compression be set in .htaccess? Or even within the script??? I suspect you could even find a PHP class out there to compress and send the right headers to do it all in PHP, regardless of server settings... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
On Wed, 2006-09-20 at 17:13 -0700, Christopher Watson wrote: I've been coding with PHP for maybe a year. So I'm somewhat new to it. But I've learned quickly, and created a fairly serious LAMP app that is capable of returning large query results. During my investigation into various means for incrementally reducing the response sizes, I've discovered output buffering with a callback function. So, as an experiment, I bracketed my includes of the Fusebox files in index.php with ob_start('sweeper') and ob_end_flush(), and placed the simple callback function at the top of the file that performs a preg_replace on the buffer to strip all excess space: function sweeper($buffer) { return preg_replace(/\s\s+/, , $buffer); } Results? Kinda nice! A large query result measuring over 900K of HTML is reduced to 600K. With no change at the browser. Still valid HTML, and the browser happily gobbles it up and displays it cleanly. It's just 30% faster getting to me. Now, the question. Is this going to bite me in the ass? 'Cause right now, it looks dang good to me. Great bang for the buck, as far as I'm concerned. I've been churning it over in my head, and I don't see a situation (certainly not in my particular app) where doing this whitespace reduction is going to backfire. There isn't anything in any of this that requires the contiguous non-word characters. I have a feeling though, that one of you more learned PHPers are going to tell me exactly where my ass is gonna start hurtin'. Should be an issue as long as you're not stripping whitespace from between pre/pre tags. Although, one must wonder why you don't just use output compression since all that whitespace would just compress anyways as would all the other content. In fact 900k with fairly standard content would shrink to about 90k. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
On Wed, 2006-09-20 at 20:21 -0400, Robert Cummings wrote: On Wed, 2006-09-20 at 17:13 -0700, Christopher Watson wrote: I've been coding with PHP for maybe a year. So I'm somewhat new to it. But I've learned quickly, and created a fairly serious LAMP app that is capable of returning large query results. During my investigation into various means for incrementally reducing the response sizes, I've discovered output buffering with a callback function. So, as an experiment, I bracketed my includes of the Fusebox files in index.php with ob_start('sweeper') and ob_end_flush(), and placed the simple callback function at the top of the file that performs a preg_replace on the buffer to strip all excess space: function sweeper($buffer) { return preg_replace(/\s\s+/, , $buffer); } Results? Kinda nice! A large query result measuring over 900K of HTML is reduced to 600K. With no change at the browser. Still valid HTML, and the browser happily gobbles it up and displays it cleanly. It's just 30% faster getting to me. Now, the question. Is this going to bite me in the ass? 'Cause right now, it looks dang good to me. Great bang for the buck, as far as I'm concerned. I've been churning it over in my head, and I don't see a situation (certainly not in my particular app) where doing this whitespace reduction is going to backfire. There isn't anything in any of this that requires the contiguous non-word characters. I have a feeling though, that one of you more learned PHPers are going to tell me exactly where my ass is gonna start hurtin'. Should be an issue That should have read shouldn't :) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
Hi Robert, Well, I think the main reason I'm not using transparent output compression is because this app shares php.ini with several other PHP apps on the server, and I don't want to foist this change on the admins of those apps. I was trying to come up with a localized strategy for trimming my app's output. The pre/pre issue is not an issue for me. -Christopher On 9/20/06, Robert Cummings [EMAIL PROTECTED] wrote: Should be an issue as long as you're not stripping whitespace from between pre/pre tags. Although, one must wonder why you don't just use output compression since all that whitespace would just compress anyways as would all the other content. In fact 900k with fairly standard content would shrink to about 90k. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
On Wed, 2006-09-20 at 17:33 -0700, Christopher Watson wrote: Hi Robert, Well, I think the main reason I'm not using transparent output compression is because this app shares php.ini with several other PHP apps on the server, and I don't want to foist this change on the admins of those apps. I was trying to come up with a localized strategy for trimming my app's output. Why settle for 30% speed boost when you can get 90% ... http://ca3.php.net/manual/en/function.ob-gzhandler.php :) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping with an OB callback
Bingo! That's the ticket. Thanks, Robert. -Christopher On 9/20/06, Robert Cummings [EMAIL PROTECTED] wrote: Why settle for 30% speed boost when you can get 90% ... http://ca3.php.net/manual/en/function.ob-gzhandler.php :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping enclosed text from PHP code
On 09/04/06, Winfried Meining [EMAIL PROTECTED] wrote: Hi, I am writing on a script that parses a PHP script and finds all function calls to check, if these functions exist. To do this, I needed a function that would strip out all text, which is enclosed in apostrophes or quotation marks. This is somewhat tricky, as the script needs to be aware of what really is an enclosed text and what is PHP code. So use the built in tokenizer functions which know exactly what's enclosed text and what is php code. Much quicker and more reliable than trying to do the same job with regular expressions. http://se.php.net/tokenizer -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping enclosed text from PHP code
Have you considered running php -s from the command line, which syntax highlights your source file for you, the searching for whatever color codes in your php.ini are used for functions? For that matter, you could custom-code the choices for the color and make the functions read in a separate php.ini On Sun, April 9, 2006 3:20 pm, Winfried Meining wrote: Hi, I am writing on a script that parses a PHP script and finds all function calls to check, if these functions exist. To do this, I needed a function that would strip out all text, which is enclosed in apostrophes or quotation marks. This is somewhat tricky, as the script needs to be aware of what really is an enclosed text and what is PHP code. Apostrophes in quotation mark enclosed text should be ignored and quotation marks in apostrophe enclosed text should be ignored, as well. Similarly, escaped apostrophes in apostrophe enclosed text and escaped quotation marks in quotation mark enclosed text should be ignored. The following function uses preg_match to do this job. ? function stripstrings($text) { while (preg_match(/^(.*)(?!\\\)('|\)(.*)$/, $text, $matches)) { $front = $matches[1]; $lim = $matches[2]; $tail = $matches[3]; while (preg_match(/^(.*)(?!\\\)('|\)(.*)$/, $front, $matches)) { $front = $matches[1]; $tail = $matches[3] . $lim . $tail; $lim = $matches[2]; } if (!preg_match(/^(.*)(?!\\\)$lim(.*)$/, $tail, $matches)) break; $string = $matches[1]; $tail = $matches[2]; while (preg_match(/^(.*)(?!\\\)$lim(.*)$/, $string, $matches)) { $string = $matches[1]; $tail = $matches[2] . $lim . $tail; } $text = $front . $tail; } return($text); } ? I noticed that this function is very slow, in particular because preg_match(/^(.*)some_string(.*)$/, $text, $matches); always seems to find the *last* occurrence of some_string and not the *first* (I would need the first). There is certainly a way to write another version where one looks at every single character when going through $text, but this would make the code much more complex. I wonder, if there is a faster *and* simple way to do the same thing. Is there btw a script freely available, which can parse PHP code and check for errors ? Any help is highly appreciated. Winfried -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping enclosed text from PHP code
http://www.phpcompiler.org/ Satyam - Original Message - From: Winfried Meining [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Sunday, April 09, 2006 10:20 PM Subject: [PHP] stripping enclosed text from PHP code Hi, I am writing on a script that parses a PHP script and finds all function calls to check, if these functions exist. To do this, I needed a function that would strip out all text, which is enclosed in apostrophes or quotation marks. This is somewhat tricky, as the script needs to be aware of what really is an enclosed text and what is PHP code. Apostrophes in quotation mark enclosed text should be ignored and quotation marks in apostrophe enclosed text should be ignored, as well. Similarly, escaped apostrophes in apostrophe enclosed text and escaped quotation marks in quotation mark enclosed text should be ignored. The following function uses preg_match to do this job. ? function stripstrings($text) { while (preg_match(/^(.*)(?!\\\)('|\)(.*)$/, $text, $matches)) { $front = $matches[1]; $lim = $matches[2]; $tail = $matches[3]; while (preg_match(/^(.*)(?!\\\)('|\)(.*)$/, $front, $matches)) { $front = $matches[1]; $tail = $matches[3] . $lim . $tail; $lim = $matches[2]; } if (!preg_match(/^(.*)(?!\\\)$lim(.*)$/, $tail, $matches)) break; $string = $matches[1]; $tail = $matches[2]; while (preg_match(/^(.*)(?!\\\)$lim(.*)$/, $string, $matches)) { $string = $matches[1]; $tail = $matches[2] . $lim . $tail; } $text = $front . $tail; } return($text); } ? I noticed that this function is very slow, in particular because preg_match(/^(.*)some_string(.*)$/, $text, $matches); always seems to find the *last* occurrence of some_string and not the *first* (I would need the first). There is certainly a way to write another version where one looks at every single character when going through $text, but this would make the code much more complex. I wonder, if there is a faster *and* simple way to do the same thing. Is there btw a script freely available, which can parse PHP code and check for errors ? Any help is highly appreciated. Winfried -- 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] Stripping control M character (^M)
Philip Hallstrom wrote: Hello All, I'm having some issues with carriage returns. Specifically the control M character (^M). I have attempted to clean and validate the file I'm creating. Here's the code. while ($row = mysql_fetch_array($result)){ // assign and clean vars $artist = trim($row[artist]); $tdDate = trim($row[start_date]); $venue = trim($row[venue]); $city = trim($row[CITY]); $state = trim($row[STATE]); $country = trim($row[COUNTRY]); $tdId = trim($row[td_id]); // create string $line = $artist|||$tdDate||$venue|$city|$state|$country|$tdId\n; // validate the string if(preg_match(/.*.|||.*.||.*.|.*.|.*.|.*.|.*.n\//, $line)){ // record is correct so write line to file fwrite($handle,$line); } } So ^M slips right by trim and my preg_match line. Where is the carriage return appearing in your line of output? Trim will remove these, but only at the beginning/end of a string so if $artist = Paul\rNowosielski that won't get cleaned up... Maybe run them through ereg_replace() using [\n\r] as a pattern? Or maybe use the m modifier? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping control M character (^M)
Hello All, I'm having some issues with carriage returns. Specifically the control M character (^M). I have attempted to clean and validate the file I'm creating. Here's the code. while ($row = mysql_fetch_array($result)){ // assign and clean vars $artist = trim($row[artist]); $tdDate = trim($row[start_date]); $venue = trim($row[venue]); $city = trim($row[CITY]); $state = trim($row[STATE]); $country = trim($row[COUNTRY]); $tdId = trim($row[td_id]); // create string $line = $artist|||$tdDate||$venue|$city|$state|$country|$tdId\n; // validate the string if(preg_match(/.*.|||.*.||.*.|.*.|.*.|.*.|.*.n\//, $line)){ // record is correct so write line to file fwrite($handle,$line); } } So ^M slips right by trim and my preg_match line. Where is the carriage return appearing in your line of output? Trim will remove these, but only at the beginning/end of a string so if $artist = Paul\rNowosielski that won't get cleaned up... Maybe run them through ereg_replace() using [\n\r] as a pattern? -philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping html tags
Your RegEx is probably fine... But you are probably missing a closing quote in lines BEFORE line 39, and PHP thinks everything up the the =^ is still part of some giant monster long string that spans multiple lines, and then it gets to the /head bit (because your opening quote is really a closing quote for something way earlier) and BAM! /head don't mean nothing useful in PHP... So all this discussion about security, strip_tags, and suchlike has nothing to do with your original problem :-) But, hey, ya learned some stuff, and that's never bad. :-) On Sun, June 5, 2005 6:36 pm, Dotan Cohen said: On 6/6/05, Richard Lynch [EMAIL PROTECTED] wrote: On Sun, June 5, 2005 7:05 am, Dotan Cohen said: I took this example from php.net, but can't figure out where I went wrong. Why does this: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); throw this error: syntax error at line 265, column 39: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); ==^ It seems to be pointing to the 'e' is 'head'. Why? Thanks. The pointing is often off by a few chars... For starters, you're not correctly using \, imho. \ is special in PHP strings. \ is ALSO special in RegEx. So your \s should be \\s, in case PHP makes \s special someday. I think the ? in there will also mess you up, maybe, as that ends PHP parsing... Though it SHOULD be kosher inside a string... -- Like Music? http://l-i-e.com/artists.htm Could well be- I certainly didn't come up with that regex myself! What would you recommend to remove any tag, and the code enclosed? For instance: I love my tagbig/tag brother would become I love my brother? Dotan http://lyricslist.com/lyrics/pages/artist_albums.php/114/Chapman%2C%20Tracy Tracy Chapman Lyrics -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping html tags
On 6/7/05, Richard Lynch [EMAIL PROTECTED] wrote: Your RegEx is probably fine... But you are probably missing a closing quote in lines BEFORE line 39, and PHP thinks everything up the the =^ is still part of some giant monster long string that spans multiple lines, and then it gets to the /head bit (because your opening quote is really a closing quote for something way earlier) and BAM! /head don't mean nothing useful in PHP... So all this discussion about security, strip_tags, and suchlike has nothing to do with your original problem :-) But, hey, ya learned some stuff, and that's never bad. :-) On Sun, June 5, 2005 6:36 pm, Dotan Cohen said: On 6/6/05, Richard Lynch [EMAIL PROTECTED] wrote: On Sun, June 5, 2005 7:05 am, Dotan Cohen said: I took this example from php.net, but can't figure out where I went wrong. Why does this: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); throw this error: syntax error at line 265, column 39: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); ==^ It seems to be pointing to the 'e' is 'head'. Why? Thanks. The pointing is often off by a few chars... For starters, you're not correctly using \, imho. \ is special in PHP strings. \ is ALSO special in RegEx. So your \s should be \\s, in case PHP makes \s special someday. I think the ? in there will also mess you up, maybe, as that ends PHP parsing... Though it SHOULD be kosher inside a string... -- Like Music? http://l-i-e.com/artists.htm Could well be- I certainly didn't come up with that regex myself! What would you recommend to remove any tag, and the code enclosed? For instance: I love my tagbig/tag brother would become I love my brother? Dotan http://lyricslist.com/lyrics/pages/artist_albums.php/114/Chapman%2C%20Tracy Tracy Chapman Lyrics PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Like Music? http://l-i-e.com/artists.htm You're right! The problem wasn't the regex- it was in getting the parge to parse. I stated that in my second post- after I figured it out. And again in another post. But the thread changed subject, as I followed it... I didn't know that there could be / are virus for mobile phones. Of course I don't need all that fancy markup- truth is that I hate it. I was modifying someone else's script and didn't want to hack it up too much. But now I see that I'm better off removing all the tags like you suggest. Thanks to everyone who contributed to this thread. From you I learn. http://lyricslist.com/lyrics/pages/artist_albums.php/425/Red%20Hot%20Chili%20Peppers Red Hot Chili Peppers Lyrics -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping html tags
Dotan Cohen wrote: I took this example from php.net, but can't figure out where I went wrong. Why does this: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); throw this error: syntax error at line 265, column 39: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); ==^ It seems to be pointing to the 'e' is 'head'. Why? Thanks. Since what time does php gives the column of the error? It seems more like javascript error. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping html tags
On 6/5/05, Marek Kilimajer [EMAIL PROTECTED] wrote: Dotan Cohen wrote: I took this example from php.net, but can't figure out where I went wrong. Why does this: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); throw this error: syntax error at line 265, column 39: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); ==^ It seems to be pointing to the 'e' is 'head'. Why? Thanks. Since what time does php gives the column of the error? It seems more like javascript error. My mistake. I was trying to parse wml. The problem wasn't in the php code, it was in the code not parsing! I just started another thread on that subject. Sorry for the false alarm. Dotan a href='http://lyricslist.com/lyrics/pages/artist_albums.php/321/Madonna'Madonna lyrics/a -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping html tags
On Sun, June 5, 2005 7:05 am, Dotan Cohen said: I took this example from php.net, but can't figure out where I went wrong. Why does this: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); throw this error: syntax error at line 265, column 39: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); ==^ It seems to be pointing to the 'e' is 'head'. Why? Thanks. The pointing is often off by a few chars... For starters, you're not correctly using \, imho. \ is special in PHP strings. \ is ALSO special in RegEx. So your \s should be \\s, in case PHP makes \s special someday. I think the ? in there will also mess you up, maybe, as that ends PHP parsing... Though it SHOULD be kosher inside a string... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping html tags
On 6/6/05, Richard Lynch [EMAIL PROTECTED] wrote: On Sun, June 5, 2005 7:05 am, Dotan Cohen said: I took this example from php.net, but can't figure out where I went wrong. Why does this: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); throw this error: syntax error at line 265, column 39: $text = preg_replace(/head(.|\s)*?(.|\s)*?\/head/i , , $text); ==^ It seems to be pointing to the 'e' is 'head'. Why? Thanks. The pointing is often off by a few chars... For starters, you're not correctly using \, imho. \ is special in PHP strings. \ is ALSO special in RegEx. So your \s should be \\s, in case PHP makes \s special someday. I think the ? in there will also mess you up, maybe, as that ends PHP parsing... Though it SHOULD be kosher inside a string... -- Like Music? http://l-i-e.com/artists.htm Could well be- I certainly didn't come up with that regex myself! What would you recommend to remove any tag, and the code enclosed? For instance: I love my tagbig/tag brother would become I love my brother? Dotan http://lyricslist.com/lyrics/pages/artist_albums.php/114/Chapman%2C%20Tracy Tracy Chapman Lyrics -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping of the last character
$recipients = '[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],'; echo str_replace(',', ', ', substr($recipients, 0, -1)); - Original Message - From: Ross [EMAIL PROTECTED] I have a large group of email addesses serperated by commas. I need to trim off the very last comma $recipients = [EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED], Also how would I add a space after every comma? to give [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] many thanks, Ross -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping of the last character
use substr($recipients,0,1); to remove the last char and ereg_replace(,, ,,$recipients); to add the spaces Hope this helps CK On Mon, Apr 18, 2005 at 12:05:42PM +0100, Ross wrote: I have a large group of email addesses serperated by commas. I need to trim off the very last comma $recipients = [EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED], Also how would I add a space after every comma? to give [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] many thanks, Ross -- 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] stripping of the last character
On Mon, April 18, 2005 5:11 am, Chris Kay said: use substr($recipients,0,1); to remove the last char and ereg_replace(,, ,,$recipients); to add the spaces If the list is *REALLY* large, http://php.net/str_replace might be a bit faster. For sure, there's no need to haul out the Ereg cannon for something this simple. :-) Hope this helps CK On Mon, Apr 18, 2005 at 12:05:42PM +0100, Ross wrote: I have a large group of email addesses serperated by commas. I need to trim off the very last comma $recipients = [EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED], Also how would I add a space after every comma? to give [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] many thanks, Ross -- 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 -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping negative number
unsigned does not equal absolute value. $num = -40; print Num: $num\n; $num = abs($num); print ABS: $num\n; will display: Num: -40 ABS: 40 http://us2.php.net/manual/en/function.abs.php Justin - Original Message - From: Roger Thomas [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Thursday, December 23, 2004 1:18 AM Subject: [PHP] stripping negative number I want to convert negative number to its positive equivalent. $num = -40; printf(Unsigned value is %u, $num); output is: Unsigned value is 4294967256 I have checked the manpages and %u seems the right format. Pls advise. -- roger --- Sign Up for free Email at http://ureg.home.net.my/ --- -- 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] stripping negative number
I believe this is because taking a value and displaying it as an unsigned value isn't the same as displaying the absolute value of a number. Ever take a calculator that does hex and decimal, enter a negative number then convert it to hex? There's no negative in hex, so you end up with something odd (like zero minus one equals max value of unsigned hex.. so -40 would be 40 below the max value or something... don't know exactly how it works but I'm guessing that's what you're getting here). You might want to just use abs() to get the absolute value of the number before displaying it. -TG = = = Original message = = = I want to convert negative number to its positive equivalent. $num = -40; printf(Unsigned value is %u, $num); output is: Unsigned value is 4294967256 I have checked the manpages and %u seems the right format. Pls advise. -- roger --- Sign Up for free Email at http://ureg.home.net.my/ --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping negative number
On Thursday 23 December 2004 16:18, Roger Thomas wrote: I want to convert negative number to its positive equivalent. $num = -40; printf(Unsigned value is %u, $num); output is: Unsigned value is 4294967256 I have checked the manpages and %u seems the right format. Pls advise. You've misunderstood what the unsigned representation means. The correct function to use is abs(). -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* No matter whether th' constitution follows th' flag or not, th' supreme court follows th' iliction returns. ollo -- Mr. Dooley */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping text from a string
Adam, Hi, I use a piece of proprietary software at work that uses weird session ID strings in the URL. A sample URL looks like: http://zed2.mdah.state.ms.us/F/CC8V7H1JF4LNBVP5KARL4KGE8AHIKP1I72JSBG6AYQSMK8YF4Y-01471?func=find-b-0 The weird session ID string changes each time you login. Anyway, how can I strip out all of the text between the last / and the ? and insert it into another variable? So in this case, the end result would be a variable containing: CC8V7H1JF4LNBVP5KARL4KGE8AHIKP1I72JSBG6AYQSMK8YF4Y-01471 You can use the parse_url() function to get just the path, and then use strrpos() to find the last / character. Finally, use substr() to extract the piece that you wanted. Example: $url_array = parse_url('http://zed2.mdah.state.ms.us/F/CC8V7H1JF4LNBVP5KARL4KGE8AHIKP1I72JSBG6AYQSMK8YF4Y-01471?func=find-b-0'); $slash_pos = strrpos($url_array['path'],'/'); $session_ID = substr($url_array['path'],$slash_pos+1); /sylikc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping content and parsing returned pages?
Hello Dustin, Monday, March 15, 2004, 2:45:06 PM, you wrote: DW I need to post to a login script, then once the page is processed, I will DW parsed the returned page for the data after logined. any help please? One word for you: snoopy Oh and one URL too: http://snoopy.sourceforge.com It will do EXACTLY what you need. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping out all illegal characters for a folder name
Joseph Szobody wrote: Folks, I'm taking some user input, and creating a folder on the server. I'm already replacing with _, and stripping out a few known illegal characters (', , /, \, etc). I need to be sure that I'm stripping out every character that cannot be used for a folder name. What's the best way to do this? Do I have to manually come up with a comprehensive list of illegal characters, and then str_replace() them one by one? I think you should use the reverse solution : have a list of authorized characters and strip out all others ones. There's gotta be a better way to do this... Joseph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping out all illegal characters for a folder name
* Thus wrote Sophie Mattoug ([EMAIL PROTECTED]): Joseph Szobody wrote: I'm taking some user input, and creating a folder on the server. I'm already replacing with _, and stripping out a few known illegal characters (', , /, \, etc). I need to be sure that I'm stripping out every character that cannot be used for a folder name. What's the best way to do this? Do I have to manually come up with a comprehensive list of illegal characters, and then str_replace() them one by one? I think you should use the reverse solution : have a list of authorized characters and strip out all others ones. I'd approach it the same way. preg_replace('/[^A-Za-z0-9_]/', '_', $dirname); Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping out all illegal characters for a folder name
Sorry for the reply to the reply, but OExpress won't let me reply to newsgroup posts... From: Sophie Mattoug [EMAIL PROTECTED] Joseph Szobody wrote: I'm taking some user input, and creating a folder on the server. I'm already replacing with _, and stripping out a few known illegal characters (', , /, \, etc). I need to be sure that I'm stripping out every character that cannot be used for a folder name. What's the best way to do this? Do I have to manually come up with a comprehensive list of illegal characters, and then str_replace() them one by one? I think you should use the reverse solution : have a list of authorized characters and strip out all others ones. That's exactly it. You need to change your way of thinking. When ever you are dealing with user input, you want to define what is GOOD and only allow that. If you try to define what is BAD, you'll leave something out. As for an answer: $safe_foldername = preg_replace('/[^a-zA-Z0-9]/','',$unsafe_foldername); That'll remove anything that's not a letter or number. Adapt to your needs. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping out all illegal characters for a folder name
[snip] Sorry for the reply to the reply, but OExpress won't let me reply to newsgroup posts... [/snip] Had to laugh... :) AND BTW Happy Thanksgiving to all of our folks who celebrate that holiday! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping out all illegal characters for a folder name
On Thursday, November 27, 2003, at 03:12 AM, Curt Zirzow wrote: I'd approach it the same way. preg_replace('/[^A-Za-z0-9_]/', '_', $dirname); I totally agree with Curt here. Justin French -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping Decimals
[snip] I currently use number_format() and str_replace() to remove a , or $ if entered and reformat it as a price for an item. I've asked the user not to use decimals but some still do. How do I remove a decimal and anything after from a number in a varable? [/snip] http://www.php.net/explode $dollar = 100.28; $newDollar = explode(., $dollar); echo $newDollar[0]; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping Decimals
From: Ed Curtis [EMAIL PROTECTED] I currently use number_format() and str_replace() to remove a , or $ if entered and reformat it as a price for an item. I've asked the user not to use decimals but some still do. How do I remove a decimal and anything after from a number in a varable? $new_number = preg_replace('/\.[0-9]+/','',$old_number); I would do that first, then a $new_number = preg_replace('/[^0-9]/','',$new_number); afterwards to remove anything that's not a number from the string. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping Decimals
Thanks! Works like a charm. Ed On Tue, 4 Nov 2003, CPT John W. Holmes wrote: From: Ed Curtis [EMAIL PROTECTED] I currently use number_format() and str_replace() to remove a , or $ if entered and reformat it as a price for an item. I've asked the user not to use decimals but some still do. How do I remove a decimal and anything after from a number in a varable? $new_number = preg_replace('/\.[0-9]+/','',$old_number); I would do that first, then a $new_number = preg_replace('/[^0-9]/','',$new_number); afterwards to remove anything that's not a number from the string. ---John Holmes... -- 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] stripping comments
On Sun, Oct 05, 2003 at 04:46:16AM -0400, zzz wrote: : : I'm trying to strip comments out of my code. I can get it to strip one : section of comments but the problem comes in when I have more then one : comment section to strip. : : I am using this: $code = preg_replace('/\/*(.*?)*\//is', '$1', $code) and : need help fixing my regex. : : example: : : code 1 : /* comment 1 */ : code 2 : /* comment 2 */ : code 3 : : result (bad): : = : code 1 : code 3 : : result (good): : == : code 1 : code 2 : code 3 How about this: $code = preg_replace('|/\*.*\*/|msU', '', $code); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping comments
You will run into more problems and there are many things you need to consider, for example /* in a string. But token_get_all() will parse php code for you and will make things much simpler. zzz wrote: I'm trying to strip comments out of my code. I can get it to strip one section of comments but the problem comes in when I have more then one comment section to strip. I am using this: $code = preg_replace('/\/*(.*?)*\//is', '$1', $code) and need help fixing my regex. example: code 1 /* comment 1 */ code 2 /* comment 2 */ code 3 result (bad): = code 1 code 3 result (good): == code 1 code 2 code 3 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] stripping comments
Hey perfect Eugene, thanks -Original Message- From: Eugene Lee [mailto:[EMAIL PROTECTED] Sent: October 5, 2003 5:14 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] stripping comments On Sun, Oct 05, 2003 at 04:46:16AM -0400, zzz wrote: : : I'm trying to strip comments out of my code. I can get it to strip one : section of comments but the problem comes in when I have more then one : comment section to strip. : : I am using this: $code = preg_replace('/\/*(.*?)*\//is', '$1', $code) and : need help fixing my regex. : : example: : : code 1 : /* comment 1 */ : code 2 : /* comment 2 */ : code 3 : : result (bad): : = : code 1 : code 3 : : result (good): : == : code 1 : code 2 : code 3 How about this: $code = preg_replace('|/\*.*\*/|msU', '', $code); -- 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] stripping comments
On Sun, 5 Oct 2003 04:46:16 -0400, you wrote: I'm trying to strip comments out of my code. I can get it to strip one section of comments but the problem comes in when I have more then one comment section to strip. I am using this: $code = preg_replace('/\/*(.*?)*\//is', '$1', $code) and need help fixing my regex. As someone already mentioned, regexes aren't the right tool for this job. Consider: echo (/*); /* test */ And while that's unlikely in real code it is /possible/, and doing it the right way is so easy due to the tokenizer functions (http://www.php.net/manual/en/ref.tokenizer.php) that it would be foolish not to. The following script prints out it's own source code, sans comments (I use something like this to replace tabs with spaces). It's adapted from a fragment in the manual. It removes /* comments */, !-- comments -- and // comments ?php $incoming = file_get_contents ($PATH_TRANSLATED); echo (strip_comments ($incoming)); function strip_comments ($in) { $out = ''; $tokens = token_get_all ($in); foreach ($tokens as $token) { if (is_string ($token)) { $out .= $token; } else { list ($id, $text) = $token; switch ($id) { case T_INLINE_HTML : $out .= preg_replace ('/!--(.|\s)*?--/', '', $text); break; case T_COMMENT : case T_ML_COMMENT : break; default : $out .= $text; break; } } } return ($out); } ? I'm reasonably certain I can get away with using a regex to strip HTML comments because SGML/XML are stricter on the placing of angle brackets. If anyone can come up with a case that breaks the regex I'll take a shot at an XSLT-based fix. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping out and URL hacking characters from a URL
Matt Babineau mailto:[EMAIL PROTECTED] on Tuesday, August 19, 2003 8:10 AM said: Does anyone have a function or something they have already written to remove any URL hacking characters, mainly the single quote, but I'm looking for a nice function to filter my _GET variables against. Gotta protect the database...ya know :) Does www.php.net/addslashes not suit your needs? c. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping out and URL hacking characters from a URL
From: Matt Babineau [EMAIL PROTECTED] Does anyone have a function or something they have already written to remove any URL hacking characters, mainly the single quote, but I'm looking for a nice function to filter my _GET variables against. Gotta protect the database...ya know :) Just escape your single quotes. That's all you need to do. Either use addslashes() if your database requires quotes to be escaped with a backslash, or use a str_replace() function if your database requires single quotes to be escaped with a single quote. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] stripping newlines from a string
How to remove new line / CrLf from a string http://examples.weberdev.com/get_example.php3?count=3577 Sincerely berber Visit http://www.weberdev.com/ Today!!! To see where PHP might take you tomorrow. -Original Message- From: Charles Kline [mailto:[EMAIL PROTECTED] Sent: Monday, June 09, 2003 7:44 AM To: [EMAIL PROTECTED] Subject: [PHP] stripping newlines from a string Hi all, How would i go about stripping all newlines from a string? Thanks, Charles -- 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] stripping newlines from a string
Yes. Is weird. I thought this would work too, but for some reason it was not removing them all. I wonder if re-saving the files with UNIX linebreaks (or try DOS) would have any effect. Will report back. - Charles On Monday, June 9, 2003, at 02:24 AM, Joe Pemberton wrote: http://www.php.net/str_replace $newstr = str_replace(\n, , $oldstr); - Original Message - From: Charles Kline [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, June 08, 2003 10:44 PM Subject: [PHP] stripping newlines from a string Hi all, How would i go about stripping all newlines from a string? Thanks, Charles -- 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] stripping newlines from a string
On Sun, 2003-06-08 at 22:44, Charles Kline wrote: Hi all, How would i go about stripping all newlines from a string? Thanks, Charles Something like this: ?php error_reporting(E_ALL); $str = This string has unix\n and Windows\r\n and Mac\r line endings.; $new_str = preg_replace('/[\n\r]+/', '', $str); echo $str; $new_str; ? Good luck, Torben -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping newlines from a string
On Mon, 9 Jun 2003, Charles Kline wrote: Yes. Is weird. I thought this would work too, but for some reason it was not removing them all. I wonder if re-saving the files with UNIX linebreaks (or try DOS) would have any effect. Will report back. $str = str_replace (array(\r, \n), '', $str); Regards, Philip On Monday, June 9, 2003, at 02:24 AM, Joe Pemberton wrote: http://www.php.net/str_replace $newstr = str_replace(\n, , $oldstr); - Original Message - From: Charles Kline [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, June 08, 2003 10:44 PM Subject: [PHP] stripping newlines from a string Hi all, How would i go about stripping all newlines from a string? Thanks, Charles -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] stripping slashes before insert behaving badly
I am inserting data from a form into a mySQL database. I am using addslashes to escape things like ' in the data input (this is actually being done in PEAR (HTML_QuickForm). The weird thing is that the data gets written into the table like: what\'s your problem? WITH the slash. I am not sure what to modify to fix this so the literal slash is not written. You're running addslashes() twice, somehow. Magic_quotes_gpc is probably on and you're escaping the data again. I would think PEAR would account for that, but I guess not. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping slashes before insert behaving badly
John, You are right, something was adding the additional slash. I removed the addslashes() and it fixed the problem. Something I am doing must already be handling that... will step through the code AGAIN and see if I can find it. - Charles On Monday, March 17, 2003, at 12:19 PM, John W. Holmes wrote: I am inserting data from a form into a mySQL database. I am using addslashes to escape things like ' in the data input (this is actually being done in PEAR (HTML_QuickForm). The weird thing is that the data gets written into the table like: what\'s your problem? WITH the slash. I am not sure what to modify to fix this so the literal slash is not written. You're running addslashes() twice, somehow. Magic_quotes_gpc is probably on and you're escaping the data again. I would think PEAR would account for that, but I guess not. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping slashes before insert behaving badly
if Magic_quotes_gpc in you php.ini is set to 'on', php will automatically escape(add slashes) for you. Foong Charles Kline [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] John, You are right, something was adding the additional slash. I removed the addslashes() and it fixed the problem. Something I am doing must already be handling that... will step through the code AGAIN and see if I can find it. - Charles On Monday, March 17, 2003, at 12:19 PM, John W. Holmes wrote: I am inserting data from a form into a mySQL database. I am using addslashes to escape things like ' in the data input (this is actually being done in PEAR (HTML_QuickForm). The weird thing is that the data gets written into the table like: what\'s your problem? WITH the slash. I am not sure what to modify to fix this so the literal slash is not written. You're running addslashes() twice, somehow. Magic_quotes_gpc is probably on and you're escaping the data again. I would think PEAR would account for that, but I guess not. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping %20 and other characters from query string
Try these: http://www.php.net/manual/en/function.urldecode.php http://www.php.net/manual/en/function.rawurldecode.php HTH, Jason k Larson Sarah Gray wrote: Hello, Forgive me if this is an obvious question, but I am passing a value (a string with spaces and quotations) back in a query string and do not know how to strip the extra characters that have been placed into it. For example. $value = Sarah's Test Page query string = mypage.php?value=Sarah\\\'s%20Test%20Page echo $value = Sarah\\\'s%20Test%20Page What is the command to strip out these extra space and escape characters so that when I echo $value it prints out Sarah's Test Page? Much Appreciated, s. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping %20 and other characters from query string
Sarah, There are a couple functions that could do this for you. Probably the fastest one for your example would be as follows. $NewString = str_replace('%20', ' ', $value); // Removes the %20 characters $NewString = str_replace '\', '', $NewString); // Removes \ character echo $NewString; http://www.php.net/manual/en/function.str-replace.php On Thursday, February 6, 2003, at 03:39 PM, Sarah Gray wrote: Hello, Forgive me if this is an obvious question, but I am passing a value (a string with spaces and quotations) back in a query string and do not know how to strip the extra characters that have been placed into it. For example. $value = Sarah's Test Page query string = mypage.php?value=Sarah\\\'s%20Test%20Page echo $value = Sarah\\\'s%20Test%20Page What is the command to strip out these extra space and escape characters so that when I echo $value it prints out Sarah's Test Page? Much Appreciated, s. -- 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] Stripping HTML tags, but keeping entities...
on 21/11/02 2:25 AM, David Russell ([EMAIL PROTECTED]) wrote: strip_tags($_POST['Duplicate'], 'B I P A LI OL UL EM BR TT STRONG BLOCKQUOTE DIV ECODE '); OK, so this is cool. I got this list from the Slashdot allowed tags list, which I would assume is ok. Whoa there... NEVER assume because someone else does something that it's okay or safe. According to your above checks, I'm allowed to do this: B onmouseover=window.close();something evil/b Strip tags does not make a post safe at all... *safer* maybe, but no where near safe. Really, what's needed is another version of strip tags which allows you to specify allowed attributes per tag: strip_tags_attr($string, 'B P class id style A href title BR') But even that wouldn't prevent people from sneaking javascript (OR OTHER CLIENT SIDE SCRIPTING) into the href attribute. But, I haven't got enough brains to actually write the extension for PHP, so hopefully someone else will pick it up eventually. In the meantime, the only solution I can think of is to not allow btags/b... perhaps allow some other form of [i]tag[/i] tag system which doesn't allow any attributes. Then you can simply strip all tags, and then go onto replacing [b] with b, etc etc. It's a lot of work, and you will run into even more work when you choose to allow [a href=] or other attributes, but it IS safer. Or, perhaps it's cheaper for you to do some preliminary stripping of tags as per your code above, and then have a moderator physically check over the code for hidden evil. Justin French http://Indent.com.au Web Developent Graphic Design -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping specific tags
I was wondering is there a way to strip ONLY the tags that you specify from a page, rather than having to include all the tags you do want (using strip_tags() ) A regular expression or str_replace() would be best for this. Realize this isn't a good method, though. What if you're trying to strip images with an img tag, but a new spec comes out that allows image tags. Now you're not protected against it. That's a simple example, but it's a better policy to say X is good and allow it through, rather than to say, I know Y is bad, but I'll let everything else through and assume it's good. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping specific tags
That's what I thought the answer would be. I guess I will have to see if I can create a function to add to the next release of PHP to do this, as there certainly seems to be quite a demand for it, according to the archives anyway. I hope not. That would be a worthless function to have. Did you read my post? The basic idea is validation is to allow what you _know_ is good, and kill the rest. You don't kill a couple things you know are bad, then assume the rest is good and let it in. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping specific tags
on 20/09/02 1:14 PM, John Holmes ([EMAIL PROTECTED]) wrote: I hope not. That would be a worthless function to have. Did you read my post? The basic idea is validation is to allow what you _know_ is good, and kill the rest. You don't kill a couple things you know are bad, then assume the rest is good and let it in. I'm with John on this one for sure... To pretend you know every possible bad thing that can happen is plain stoopid. Develop a list of things you accept (commonly pbibr), and turf the rest. What I WOULD like to see in a future PHP release is a strip attributes feature. Not sure of how to implement it, but even if you only let a few tags through, there are still BIG problems with the tags: B onclick=javascript: window.close() (not sure of the exact syntax) is pretty evil. Perhaps if strip tags could be extended so that you can list ALLOWED attributes: $string = striptags2('P class id styleBIBRA href target', $string) Essentially, this would kill off any one doing an onclick/onmouseover/etc on the allowed tags This still leaves a few problems, the biggest of which is href=javascript:... in a tags. A further extension might be to list the allowed protocols of href?? There could be an allowance for http, ftp, ext (external), rel (relative links), javascript, and others I'm not thinking about. striptags2('bA href[rel] target', $string) would only allow relative links striptags2('bA href[http|ftp|rel] target', $string) would only allow relative, http and ftp links... NOT javascript for example This would make striptags() a HIGHLY powerful tool for validating user input which contains HTML. yes, it can all be done with regexp if you've got enough time and skills, but I don't :) Sorry for getting off topic!! Regards, Justin French -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping illegal characters out of an XML document
On Thu, Jun 06, 2002 at 12:47:57PM +0100, Daniel Pupius wrote: Hi there. I'm working with RDF/XML that is strict on what characters are allowed within the elements and attributes. I was wondering if anyone had a script that processed a string and replaced all illegal-characters with their HTML code, for example is converted to and to . It should also work for characters like é. Here's what I use. I grab the file and stick it into the $Contents string. Then, I clean it up with the following regex's. Finally, I pass it to the parse function. # Escape ampersands. $Contents = preg_replace('/(amp;|)/i', 'amp;', $Contents); # Remove all non-visible characters except SP, TAB, LF and CR. $Contents = preg_replace('/[^\x20-\x7E\x09\x0A\x0D]/', \n, $Contents); Of course, you can similarly tweak $Contents to drop or modify any other characters you wish. That's snipet is from my PHP XML Parsing Basics tutorial at http://www.analysisandsolutions.com/code/phpxml.htm It would be possible to process the strings before they are inserted into the XML document - if that is easier. While that's nice, it's not fool proof. What if someone circumvents your insertion process and gets a bad file into the mix? You still need to clean things as they come out just to be safe. Enjoy, --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping illegal characters out of an XML document
Thanks, I've created a delimited file of all the HTML Character references. I then loop through and do a replace as previously suggested. However, IE's XML Parser still doesn't like the eacute; which represents é For all intents and purposes it's ok and works with the RDF processor. However, I'd like IE to be able to view the XML file just for completeness. Da Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Thu, Jun 06, 2002 at 12:47:57PM +0100, Daniel Pupius wrote: Hi there. I'm working with RDF/XML that is strict on what characters are allowed within the elements and attributes. I was wondering if anyone had a script that processed a string and replaced all illegal-characters with their HTML code, for example is converted to and to . It should also work for characters like é. Here's what I use. I grab the file and stick it into the $Contents string. Then, I clean it up with the following regex's. Finally, I pass it to the parse function. # Escape ampersands. $Contents = preg_replace('/(amp;|)/i', 'amp;', $Contents); # Remove all non-visible characters except SP, TAB, LF and CR. $Contents = preg_replace('/[^\x20-\x7E\x09\x0A\x0D]/', \n, $Contents); Of course, you can similarly tweak $Contents to drop or modify any other characters you wish. That's snipet is from my PHP XML Parsing Basics tutorial at http://www.analysisandsolutions.com/code/phpxml.htm It would be possible to process the strings before they are inserted into the XML document - if that is easier. While that's nice, it's not fool proof. What if someone circumvents your insertion process and gets a bad file into the mix? You still need to clean things as they come out just to be safe. Enjoy, --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping illegal characters out of an XML document
Heya: On Thu, Jun 06, 2002 at 04:54:15PM +0100, Daniel Pupius wrote: Thanks, I've created a delimited file of all the HTML Character references. I then loop through and do a replace as previously suggested. However, IE's XML Parser still doesn't like the eacute; which represents é For all intents and purposes it's ok and works with the RDF processor. However, I'd like IE to be able to view the XML file just for completeness. Try #233; and see if IE likes that. If not, on the way out to the browser, you can convert your escaping back to an é. Ciao! --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping characters.....
Clarification: So really, what you want to achieve is to ONLY have the email address? I'm POSITIVE there's a better way with ereg_replace(), but I haven't got time to experiment, and i'm no expert :) So, what I figured was that you would loop through the $email, and if the first char wasn't a , strip it out: Chris Ditty [EMAIL PROTECTED] Chris Ditty [EMAIL PROTECTED] hris Ditty [EMAIL PROTECTED] ris Ditty [EMAIL PROTECTED] is Ditty [EMAIL PROTECTED] ... [EMAIL PROTECTED] You're then left with something. Assuming all your address' are wrapped in ... , you'll now have [EMAIL PROTECTED]. Then, you want to strip out the leading and the trailing only (this means weird email address' which have a or in them won't break. You should now have [EMAIL PROTECTED] UNTESTED code: ? $email = 'Chris Ditty mail@redhotsweeps.com'; while (!eregi('^', $email)) { $email = substr($email, 1); //echo htmlspecialchars($email).BR; } $email = ereg_replace(^, , $email); $email = ereg_replace($, , $email); echo htmlspecialchars($email).BR; ? Like I said, this is probably NOT the best solution, just *a* solution, but it should work. It's independent of the 's you had in there... all it cares about is $email ending with something, getting rid of the preceeding it, and then getting rid of the 's that wrap it. You might also like to get rid of anything trailing the . Uncomment line 6 to watch the progress of the while loop :) Justin French Creative Director http://Indent.com.au on 28/04/02 4:16 PM, CDitty ([EMAIL PROTECTED]) wrote: Hello all, Does anyone have any snippets of code that will strip several characters from a string? I am trying to figure out how to do this without using 3 different if statement blocks. This is what I am looking for. ieUser email address is Chris Ditty [EMAIL PROTECTED] or Chris Ditty [EMAIL PROTECTED] I need to be able to strip the quotes and everything between them and the signs from the first one and then the name and the signs from the second. Does anyone know how to do this quickly and easily? Thanks CDitty -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping the first line of a file
Use $aFile=file(FILENAME); //$aFile[0] contains the unwanted line echo $aFile[1]; // displays line 2 echo $aFile[n]; // displays line n where n is an positieve interger and not greater then the number of lines in the file http://www.php.net/manual/en/function.file.php HTH Jerry -Original Message- From: Scott [mailto:[EMAIL PROTECTED]] Sent: Friday, February 08, 2002 4:02 PM To: [EMAIL PROTECTED] Subject: [PHP] Stripping the first line of a file Hi, I want to be able to open a file and then strip the first line of it off. Example, the first line contains the names for tables in a database and all I need is from the second line on. if I fopen a file can I strip the line or should I process it and then drop the data from the first row? Thanks, -Scott -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The information contained in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any form of disclosure, production, distribution or any action taken or refrained from in reliance on it, is prohibited and may be unlawful. Please notify the sender immediately. The content of the email is not legally binding unless confirmed by letter bearing two authorized signatures. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping the first line of a file
Thank you! Works. I have a few more questions! I am working on converting a program from perl to PHP as it is the new language of choice at our office. I have been using printf statements in perl to format data. Is there a similar funtion in php? Here is an example from the perl program: printf NEW (%-5.5s,$fields[14]); This will print exactly 5 characters, I also use this format to make sure the lines are exactly 255 characters long: printf NEW (%-193.193s); Is there something similar in php. Thanks for everyone's help and patience. -Scott On Fri, 8 Feb 2002, Jerry Verhoef (UGBI) wrote: $aFile=file(FILENAME); //$aFile[0] contains the unwanted line echo $aFile[1]; // displays line 2 echo $aFile[n]; // displays line n where n is an positieve interger and not greater then the number of lines in the file -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping the first line of a file
Yes there is! Try reading the manual? http://www.php.net/printf printf (%-5.5s,$fields[14]); for the other function to make a line exactly 255 char long? Do you have the perl Example? HTH Jerry -Original Message- From: Scott [mailto:[EMAIL PROTECTED]] Sent: Friday, February 08, 2002 4:22 PM To: Jerry Verhoef (UGBI) Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Stripping the first line of a file Thank you! Works. I have a few more questions! I am working on converting a program from perl to PHP as it is the new language of choice at our office. I have been using printf statements in perl to format data. Is there a similar funtion in php? Here is an example from the perl program: printf NEW(%-5.5s,$fields[14]); This will print exactly 5 characters, I also use this format to make sure the lines are exactly 255 characters long: printf NEW(%-193.193s); Is there something similar in php. Thanks for everyone's help and patience. -Scott On Fri, 8 Feb 2002, Jerry Verhoef (UGBI) wrote: $aFile=file(FILENAME); //$aFile[0] contains the unwanted line echo $aFile[1]; // displays line 2 echo $aFile[n]; // displays line n where n is an positieve interger and not greater then the number of lines in the file -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The information contained in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any form of disclosure, production, distribution or any action taken or refrained from in reliance on it, is prohibited and may be unlawful. Please notify the sender immediately. The content of the email is not legally binding unless confirmed by letter bearing two authorized signatures. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping the first line of a file
printf NEW (%-193.193s); printf (%-193.193s,VARIABLE); HTH -Original Message- From: Jerry Verhoef (UGBI) [mailto:[EMAIL PROTECTED]] Sent: Friday, February 08, 2002 4:35 PM To: 'Scott'; Jerry Verhoef (UGBI) Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Stripping the first line of a file Yes there is! Try reading the manual? http://www.php.net/printf printf (%-5.5s,$fields[14]); for the other function to make a line exactly 255 char long? Do you have the perl Example? HTH Jerry -Original Message- From: Scott [mailto:[EMAIL PROTECTED]] Sent: Friday, February 08, 2002 4:22 PM To: Jerry Verhoef (UGBI) Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Stripping the first line of a file Thank you! Works. I have a few more questions! I am working on converting a program from perl to PHP as it is the new language of choice at our office. I have been using printf statements in perl to format data. Is there a similar funtion in php? Here is an example from the perl program: printf NEW (%-5.5s,$fields[14]); This will print exactly 5 characters, I also use this format to make sure the lines are exactly 255 characters long: printf NEW (%-193.193s); Is there something similar in php. Thanks for everyone's help and patience. -Scott On Fri, 8 Feb 2002, Jerry Verhoef (UGBI) wrote: $aFile=file(FILENAME); //$aFile[0] contains the unwanted line echo $aFile[1]; // displays line 2 echo $aFile[n]; // displays line n where n is an positieve interger and not greater then the number of lines in the file -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The information contained in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any form of disclosure, production, distribution or any action taken or refrained from in reliance on it, is prohibited and may be unlawful. Please notify the sender immediately. The content of the email is not legally binding unless confirmed by letter bearing two authorized signatures. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The information contained in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any form of disclosure, production, distribution or any action taken or refrained from in reliance on it, is prohibited and may be unlawful. Please notify the sender immediately. The content of the email is not legally binding unless confirmed by letter bearing two authorized signatures. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Stripping the first line of a file
Thanks Jerry! In perl I was doing this: printf NEW (%-193.193s); Which I just read the manual and discovered it works in PHP as well. Basically prints 193 spaces to make sure the line is 255 after I filled the line with other characters. On Fri, 8 Feb 2002, Jerry Verhoef (UGBI) wrote: Yes there is! Try reading the manual? http://www.php.net/printf printf (%-5.5s,$fields[14]); for the other function to make a line exactly 255 char long? Do you have the perl Example? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stripping slashes from db-insert?
Addslashes() is probably getting called twice on the data on the insert... if you have magic_gpc on, any inputted data already has the necessary escapes - so you shouldnt need to call it again... Hope that helped :) -- Shane On Saturday 01 Dec 2001 1:14 pm, Daniel Alsén wrote: Hi, i know this has been asked before - but: When i add entries to MySql (varchar and text) all and ' gets a slash in front of them. How do i get rid of these slashes? Regards # Daniel Alsén| www.mindbash.com # # [EMAIL PROTECTED] | +46 704 86 14 92 # # ICQ: 63006462 | +46 8 694 82 22 # # PGP: http://www.mindbash.com/pgp/ # -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Stripping single quotes
Darn, it still 'aint working. Ok, let's say $fldemail contains o\'[EMAIL PROTECTED] I then run these: $fldemail == stripslashes($fldemail); $fldemail == ereg_replace(',,$fldemail); And I get o\'[EMAIL PROTECTED] ... damn. Any ideas? Thanks, Matt Stone -Original Message- From: Chris Fry [mailto:[EMAIL PROTECTED]] Sent: Saturday, 28 July 2001 2:15 PM To: Matt Stone Cc: PHP list Subject: Re: [PHP] Stripping single quotes Matt, Try ereg_replace:- $fldemail == ereg_replace(',,$fldemail); Chris Matt Stone wrote: Hi all, I am trying to validate some email addresses before they are entered into the database. The problem is, some thick or malicious people are entering single quotes into their email addresses. I need to strip out all these single quotes but a little ole' str_replace doesn't seem to be working. Here it is: $fldemail == str_replace(',,$fldemail); Nice and basic :) Can anyone please enlighten me on this? Thanks in advance, Matt Stone -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Chris Fry Quillsoft Pty Ltd Specialists in Secure Internet Services and E-Commerce Solutions 10 Gray Street Kogarah NSW 2217 Australia Phone: +61 2 9553 1691 Fax: +61 2 9553 1692 Mobile: 0419 414 323 eMail: [EMAIL PROTECTED] http://www.quillsoft.com.au You can download our Public CA Certificate from:- https://ca.secureanywhere.com/htdocs/cacert.crt ** This information contains confidential information intended only for the use of the authorised recipient. If you are not an authorised recipient of this e-mail, please contact Quillsoft Pty Ltd by return e-mail. In this case, you should not read, print, re-transmit, store or act in reliance on this e-mail or any attachments, and should destroy all copies of them. This e-mail and any attachments may also contain copyright material belonging to Quillsoft Pty Ltd. The views expressed in this e-mail or attachments are the views of the author and not the views of Quillsoft Pty Ltd. You should only deal with the material contained in this e-mail if you are authorised to do so. This notice should not be removed. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Stripping single quotes
I'd have a look at those double equals signs ... I think they should be single: $fldemail = stripslashes($fldemail); $fldemail = ereg_replace(',,$fldemail); Mick On Sat, 28 Jul 2001, Matt Stone wrote: Darn, it still 'aint working. Ok, let's say $fldemail contains o\'[EMAIL PROTECTED] I then run these: $fldemail == stripslashes($fldemail); $fldemail == ereg_replace(',,$fldemail); And I get o\'[EMAIL PROTECTED] ... damn. Any ideas? Thanks, Matt Stone -Original Message- From: Chris Fry [mailto:[EMAIL PROTECTED]] Sent: Saturday, 28 July 2001 2:15 PM To: Matt Stone Cc: PHP list Subject: Re: [PHP] Stripping single quotes Matt, Try ereg_replace:- $fldemail == ereg_replace(',,$fldemail); Chris Matt Stone wrote: Hi all, I am trying to validate some email addresses before they are entered into the database. The problem is, some thick or malicious people are entering single quotes into their email addresses. I need to strip out all these single quotes but a little ole' str_replace doesn't seem to be working. Here it is: $fldemail == str_replace(',,$fldemail); Nice and basic :) Can anyone please enlighten me on this? Thanks in advance, Matt Stone -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Chris Fry Quillsoft Pty Ltd Specialists in Secure Internet Services and E-Commerce Solutions 10 Gray Street Kogarah NSW 2217 Australia Phone: +61 2 9553 1691 Fax: +61 2 9553 1692 Mobile: 0419 414 323 eMail: [EMAIL PROTECTED] http://www.quillsoft.com.au You can download our Public CA Certificate from:- https://ca.secureanywhere.com/htdocs/cacert.crt ** This information contains confidential information intended only for the use of the authorised recipient. If you are not an authorised recipient of this e-mail, please contact Quillsoft Pty Ltd by return e-mail. In this case, you should not read, print, re-transmit, store or act in reliance on this e-mail or any attachments, and should destroy all copies of them. This e-mail and any attachments may also contain copyright material belonging to Quillsoft Pty Ltd. The views expressed in this e-mail or attachments are the views of the author and not the views of Quillsoft Pty Ltd. You should only deal with the material contained in this e-mail if you are authorised to do so. This notice should not be removed. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Michael Hall mulga.com.au [EMAIL PROTECTED] ph/fax (+61 8) 8953 1442 ABN 94 885 174 814 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Stripping single quotes
Thanks for your help everyone, I feel pretty embarrassed to have made a mistake like that! :o -Original Message- From: Bojan Gajic [mailto:[EMAIL PROTECTED]] Sent: Sunday, 29 July 2001 12:44 AM To: Matt Stone Subject: Re: [PHP] Stripping single quotes you are not assigning stripslashes($fldemail) to the $fldemail, you are maching them. use '=' instead of '= =' hth, bojan Matt Stone wrote: Darn, it still 'aint working. Ok, let's say $fldemail contains o\'[EMAIL PROTECTED] I then run these: $fldemail == stripslashes($fldemail); $fldemail == ereg_replace(',,$fldemail); And I get o\'[EMAIL PROTECTED] ... damn. Any ideas? Thanks, Matt Stone -Original Message- From: Chris Fry [mailto:[EMAIL PROTECTED]] Sent: Saturday, 28 July 2001 2:15 PM To: Matt Stone Cc: PHP list Subject: Re: [PHP] Stripping single quotes Matt, Try ereg_replace:- $fldemail == ereg_replace(',,$fldemail); Chris Matt Stone wrote: Hi all, I am trying to validate some email addresses before they are entered into the database. The problem is, some thick or malicious people are entering single quotes into their email addresses. I need to strip out all these single quotes but a little ole' str_replace doesn't seem to be working. Here it is: $fldemail == str_replace(',,$fldemail); Nice and basic :) Can anyone please enlighten me on this? Thanks in advance, Matt Stone -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Chris Fry Quillsoft Pty Ltd Specialists in Secure Internet Services and E-Commerce Solutions 10 Gray Street Kogarah NSW 2217 Australia Phone: +61 2 9553 1691 Fax: +61 2 9553 1692 Mobile: 0419 414 323 eMail: [EMAIL PROTECTED] http://www.quillsoft.com.au You can download our Public CA Certificate from:- https://ca.secureanywhere.com/htdocs/cacert.crt ** This information contains confidential information intended only for the use of the authorised recipient. If you are not an authorised recipient of this e-mail, please contact Quillsoft Pty Ltd by return e-mail. In this case, you should not read, print, re-transmit, store or act in reliance on this e-mail or any attachments, and should destroy all copies of them. This e-mail and any attachments may also contain copyright material belonging to Quillsoft Pty Ltd. The views expressed in this e-mail or attachments are the views of the author and not the views of Quillsoft Pty Ltd. You should only deal with the material contained in this e-mail if you are authorised to do so. This notice should not be removed. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] stripping white space?
Hi Brian, * Persuade someone at Zend to modify PHP so that a filter function can be specified which all output text is passed through - would have the same restrictions as the header function You can already achieve this by using the built-in output buffering function. Read http://www.zend.com/manual/function.ob-start.php for more information and a simple example on this. Why not go for HTTP compression though? The gain would be much larger than just stripping out the whitespace/comments and such.. Have fun, Bart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] stripping white space?
I guess this is just one of those things where everyone's opinions runs in different directions, yet everyone is entitled to their own. I myself try to respect the standard because of the browser war years which made everyone uncomfortable. Now most browsers are trying to merge into a single standard (thank god). I believe the future to be XML, and I also don't think HTML will ever go away. However, I do believe that HTML will be treated more strict (hence the emergence of XHTML which is based on HTML 4.0 and XML). My suggestion to everyone is to continue using standards and try not to go astray from them, else we know the headaches us developers can face in the future. Sincerely, Navid Yar -Original Message- From: Maxim Maletsky [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 10, 2001 1:06 AM To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED] Subject: RE: [PHP] stripping white space? Yeah, I know that XML requires it. And I also know that it is not a good code practice, but it perfectly works for HTML pages. Browsers compatible with the style sheets have no problems with this code (there's no connection), and if there's any XML to work on the HTML will be rewritten anyway, so there's really no reason to worry about it. Just the size gets lower and typing (escaping in PHP) is easier. I think it IS a good practice if you only practicing HTML to be outputted by PHP. Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Navid A. Yar [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 10, 2001 2:40 PM To: [EMAIL PROTECTED] Subject: RE: [PHP] stripping white space? If you do this then those who will want to eventually convert their projects over to XML or XHTML format will have a hard time doing so, because the double quotes around the values of the attributes are required. Also, it's not good code practice. Just something for future reference... -Original Message- From: Maxim Maletsky [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 10, 2001 12:16 AM To: '[EMAIL PROTECTED]'; Kurt Lieber; [EMAIL PROTECTED] Subject: RE: [PHP] stripping white space? I would not be stripping white spaces, but double white spaces into single ' '; for example: $html = ereg_replace([[:space:]]+, ' ', $page); I never tested this, but what I am trying to do is to get all and any blank characters and replace them with one single space. Why? Because I don't want all the words in text to merge together. This should reduce the size. Also here's a tip: remove any double or single quotes in tags surrounding integers. This is compatible enough, but is a bunch of bytes. i.e.: change every IMG SRC=/img/arrow.gif WIDTH=12 HEIGHT=11 BORDER=0 ALT=arrow align=left to IMG SRC=/img/arrow.gif WIDTH=12 HEIGHT=11 BORDER=0 ALT=arrow align=left this example is reduced by 6 bytes. Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Mukul Sabharwal [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 10, 2001 2:05 PM To: Kurt Lieber; [EMAIL PROTECTED] Subject: Re: [PHP] stripping white space? Hi, I take that you simply want to remove ALL whitespaces from a data block (variable). you could simply use str_replace( , , $var); --- Kurt Lieber [EMAIL PROTECTED] wrote: Is there a way using PHP to easily strip white space out of an html page as it's being sent to the client. That is to say, the page that we as developers work on is nicely formatted, indented, etc. but when it's sent out to the client, PHP will remove all the extra white space both to obfuscate the code and reduce the size a bit. For anyone who knows Cold Fusion, I'm looking for the PHP equivalent of the Suppress whitespace by default option in the Cold Fusion Server Administrator. (NOTE: I'm not looking for a discussion on the merits of stripping vs. not stripping white space characters or whether or not it really does any good -- I just want to know if it can be done easily using PHP) Thanks. --kurt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] = * http://www.geocities.com/mimodit * __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED
Re: [PHP] stripping white space?
Hi Maxim, 1. HTTP compression, which is not 100% compatible, but catches most of the browsers anyway. Yes. The standard PHP implementation actually inspects the HTTP headers to determine if the browser supports gzip encoding. If not, it will send the files uncompressed. Looking at our website stats, 97%+ of the people use a version 4 browser so they're fine. 2. Our own caching system: in two words: ob_*() to save the output as a text file, mod_rewrite to check for file and throw the plain .txt files if exist, PostgreSQL triggers to update (delete cached) .txt files. Hah! We think alike :) I implemented a similar system on our own website a few weeks ago. It does not cache complete pages (that's hardly possible due to the dynamic nature of our site), but instead caches HTML 'blocks'. (one page can consist of multiple blocks). Instead of serving those files directly from the filesystem I let PHP inspect them first: each file contains a timestamp that allows for expiry times. The results are wonderful: our website (http://www.blender.nl) has approximately 80.000 pageviews a day and the system load is almost never higher than 0.4. (Dual PIII/450/512MB/FreeBSD) If people are interested I'll publish the code for the caching module. 3. Browser/Platform detection: there's no need to make cross-platform heavy but compatible pages, just specific style sheets and html tags for specific browser families. Clever! That's something I will put on my to-do list as well. 4. clever HTML design, so there are less tags, tables etc, to have files smaller. And *that* also includes less comments and double quotes on integers. We do nothing with XML, so that is why I am so shocked why people here discourage me that much. In my experience once you use HTTP compression, adding a few comments or whitelines do hardly add to the filesize anymore. I don't think it's worth the trouble to write super-compact HTML. I don't know a single thing about XML, so I'll skip that discussion :) Bart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] stripping white space?
Hi Maxim, I wrote a mini-manual about the module. You can get it with the code from: http://helium.homeip.net/stuff/cache.tar.gz I hope it helps you and I look forward to suggestions and contributions! Bart Maxim Maletsky [EMAIL PROTECTED] wrote in message news:DC017B079D81D411998C009027B7112A015ED390@EXC-TYO-01... /cache/data/articles/0-24/... /cache/data/articles/25-50/... /cache/data/searches/... this was our original idea, the difficulty is that there's the need to access this directory from several places (mod_rewrite, php and postrges). It is easy to access but might be hard to combine the URL together. But you're right, on UNIX systems, if I am not wrong, you cannot hold more then 1024 (?) files in a single directory. So subfolders is the way to go. Cheers, Maxim Maletsky -Original Message- From: Bart Veldhuizen [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 10, 2001 6:07 PM To: Maxim Maletsky; [EMAIL PROTECTED] Subject: Re: [PHP] stripping white space? Hi Maxim, I am definitely interested in seeing your caching modules - it could be a useful resource for ours. Right now our caching module is only in the planning stage, but there are few scratches I wrote myself, and it seems to be very promising. I'll do my best to write a short blurb on how to use it today and publish the code. I also have to do a zillion other things (like work on my new house), so I can't promise it'll actually be there today! There's a directory called /cached which we will store the file with the exactly same file names (with mod_rewrite there's no need to use any ?var=valetc=etc, you just get it looking like a directory) so it is extremely easy to locate a file. ie: if you go to a file articles/2000/10/26/features/doom then apache looks first into cached/articles-2000-10-26-features-doom.txt I can see one problem that you're gonna run into and that is that this directory will contain thousands of files. Not many OS's can handle that. In our case, each article has an article ID and the caching module automatically creates subdirectories that will hold a number of cached pages. Additionally, I can assign page 'types' to a page. These will generate new subdirectories as well. My caching directory looks like this: /cache/data/articles/0-24/... /cache/data/articles/25-50/... /cache/data/searches/... Have fun, Bart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] stripping white space?
Hi Remo, PS: Can anyone enlighten me concerning HTTP compression? I wish I could remember where I read this, but the PHP documentation still does not have this feature described. To enable zlib output compression, first make sure you have compiled PHP with the --with-zlib option. Next, add the following line to php.ini: zlib.output_compression = On That's all there is to it! Have fun, Bart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] stripping white space?
there is a limit of # of root entries. But the number of files per directory is much higher. Running RH6.2 I tried this test: I have an SGI xfs partition that does billion of entries per directory, like reiser, but for an ext2 partition this perl script is for testing for ($index = 1; $index = 2097153; $index++) { open (OUT, file_$index.txt); print OUT Test\n; close (OUT); } after letting it run 4 hours :) it seems to stop at 811626 where I run out of disk space :) oh well -Original Message- From: Christian Reiniger [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 10, 2001 9:52 AM To: Maxim Maletsky; 'Bart Veldhuizen'; [EMAIL PROTECTED] Subject: Re: [PHP] stripping white space? On Tuesday 10 July 2001 11:26, Maxim Maletsky wrote: But you're right, on UNIX systems, if I am not wrong, you cannot hold more then 1024 (?) files in a single directory. AFAIK there's no limit (and certainly not 1024 files), but with most filesystems accesses on large directories are painfully slow. FSs such as ReiserFS however don't slow down noticeably on large directories... -- Christian Reiniger LGDC Webmaster (http://lgdc.sunsite.dk/) I sat laughing snidely into my notebook until they showed me a PC running Linux. And oh! It was as though the heavens opened and God handed down a client-side OS so beautiful, so graceful, and so elegant that a million Microsoft developers couldn't have invented it even if they had a hundred years and a thousand crates of Jolt cola. - LAN Times -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]