[PHP] String is not zero-terminated in zend_execute_API.c
Hello List, i am running PHP 5.3.8-FPM (with ondemand patch) in debug mode and got this error every time I post an reply in vBulletin Board: Warnung: String is not zero-terminated (Z.ý4 ý4 ú}µóU) (source: /usr/src/php-5.3.8/Zend/zend_execute_API.c:447) in [path]/includes/functions_newpost.php(668) : eval()'d code (Zeile 34) functions_newpost.php: 29 if (!$allowicons) 30 { 31 return false; 32 } 33 34 $membergroups = fetch_membergroupids_array($vbulletin-userinfo); 35 $infractiongroups = explode(',', str_replace(' ', '', $vbulletin-userinfo['infractiongroupids'])); 36 37 ($hook = vBulletinHook::fetch_hook('posticons_start')) ? eval($hook) : false; 38 function fetch_membergroupids_array($user, $getprimary = true) { if (!empty($user['membergroupids'])) { $membergroups = explode(',', str_replace(' ', '', $user['membergroupids'])); } else { $membergroups = array(); } if ($getprimary) { $membergroups[] = $user['usergroupid']; } return array_unique($membergroups); } I hope you can help, or may i open an bugreport to bugs.php.net ? Greetings, Daniel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String eval assistance
On 16 March 2011 00:25, Jack jacklistm...@gmail.com wrote: Here you're trying to access it as an array, which it's not, so the 'response' key doesn't exist. In addition, you're looking for UPPER-CASE, whereas that's not the case in your example variable. Finally, you're checking to make sure that the string IS INDEED found, but then printing that it was declined (!== false). Instead, you may want: ?php $results['response'] = '3434approd34'; if (stripos($results['response'],'APPROVED') !== false) { // It's been found } else { // Oh, crap. } ? maybe I should do this some other way because I'm getting false positives. I was using if(strpos($results['response'], 'APPROVED') !== false) { And its found if the value of $results = 3434APPROVED34 and it also is found if its $results = 3434APPOVED34, so this may not be the best way to accomplish this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Can you create a small list of actual values and their results. What version of PHP are you using? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String eval assistance
I'm not sure as to why strpos does what it does here, at least its not immediately obvious, but, a solution to this would be to use a regular expression search, it would be more exact, it has never failed me, and it will be faster; I recall reading that preg functions were faster at then str ones, though I can't recall where... -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. Richard Quadling rquadl...@gmail.com wrote: On 16 March 2011 00:25, Jack jacklistm...@gmail.com wrote: Here you're trying to access it as an array, which it's not, so the 'response' key doesn't exist. In addition, you're looking for UPPER-CASE, whereas that's not the case in your example variable. Finally, you're checking to make sure that the string IS INDEED found, but then printing that it was declined (!== false). Instead, you may want: ?php $results['response'] = '3434approd34'; if (stripos($results['response'],'APPROVED') !== false) { // It's been found } else { // Oh, crap. } ? maybe I should do this some other way because I'm getting false positives. I was using if(strpos($results['response'], 'APPROVED') !== false) { And its found if the value of $results = 3434APPROVED34 and it also is found if its $results = 3434APPOVED34, so this may not be the best way to accomplish this.-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Can you create a small list of actual values and their results. What version of PHP are you using? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String eval assistance
On 16/03/2011, at 10:34 AM, Jack wrote: Hello All, I got some help on this yesterday, but somehow it's not consistant ? $results = 3434approd34; if(strpos($results['response'], 'APPROVED') !== false) { print declined; } else { print approved; } ? The thing is I cant get a consistant response, if it has approved anywhere in the results string, then it should be approved and if the results is APPROVD without the E it shold be delined. Am I doing something wrong. Thanks! Jack Yes, you're doing something wrong. strpos() returns false if it can't find the needle. You should be using if(strpos() === false) { declined; } --- Simon Welsh Admin of http://simon.geek.nz/ Who said Microsoft never created a bug-free program? The blue screen never, ever crashes! http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String length output in php-generated response
-Original Message- From: Florin Jurcovici [mailto:florin.jurcov...@gmail.com] Sent: 06 February 2011 15:57 I'm trying to build myself a small JSON-RPC server using PHP. Using wireshark, here's the conversation: Request: [...snip...] Response: HTTP/1.1 200 OK Date: Sun, 06 Feb 2011 15:04:08 GMT Server: Apache/2.2.14 (Ubuntu) Accept-Ranges: bytes X-Powered-By: PHP/5.3.2-1ubuntu4.7 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: application/json; charset=UTF-8 6f {id:2,result:{service:test.service,method:method, id:2,params:[{code:client}]},error:null} 0 That's nothing to do with PHP -- it's http chunked encoding, as indicated by the Transfer-Encoding: chunked header, and is handled by Apache and your browser. It's totally expected and totally harmless. Read about it here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6 Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507 City Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String length output in php-generated response
On 6 February 2011 15:57, Florin Jurcovici florin.jurcov...@gmail.com wrote: said it, Bush junior proved it Is this actually part of the output? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String length output in php-generated response
Hi. I'm trying to build myself a small JSON-RPC server using PHP. Using wireshark, here's the conversation: Request: POST /.../service.php?nocache=1297004648751 HTTP/1.1 User-Agent: Opera/9.80 (X11; Linux i686; U; en) Presto/2.7.62 Version/11.01 Host: localhost Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1 Accept-Language: en-US,en;q=0.9 Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1 Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0 Referer: http://localhost/ssd/php/testrpc/build/ Connection: Keep-Alive, TE TE: deflate, gzip, chunked, identity, trailers Content-Length: 80 Content-Type: application/json Pragma: no-cache Cache-Control: no-cache X-Qooxdoo-Response-Type: application/json Content-Transfer-Encoding: binary {service:test.service,method:method,id:1,params:[{code:client}]} said it, Bush junior proved it Response: HTTP/1.1 200 OK Date: Sun, 06 Feb 2011 15:04:08 GMT Server: Apache/2.2.14 (Ubuntu) Accept-Ranges: bytes X-Powered-By: PHP/5.3.2-1ubuntu4.7 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: application/json; charset=UTF-8 6f {id:2,result:{service:test.service,method:method,id:2,params:[{code:client}]},error:null} 0 The code to handle the request is: ?php $request = json_decode($GLOBALS['HTTP_RAW_POST_DATA']); $response = (object) array( id = $request-id, result = $request, error = null ); header(Content-Type: application/json; charset=UTF-8, true); print json_encode($response); ? The 6f above is the length of the output in hex (I tried with various lengths of the string, it is always correct), the 0 at the end is probably some C-like string termination mark. Now, it seems the client (some JavaScript running in Firefox) has no problem decoding the answer, in spite of the hex length placed at the beginning. However, I can't rely on browsers playing nicely with incorrect JSON, so I would very much like to generate an output without the length of the response written as hex at the beginning, and without the terminating 0. What am I doing wrong? Why does the length of the string get written? I tried concatenation of an empty string at the beginning and at the end, supposing that for some reason json_encode() doesn't produce a plain string, and hoping that concatenating it to a proper string would produce a plain string, but it didn't help either. Before posting to the list, I tried searching for the problem on the web, and also experimented by outputting plain, hand-written strings. It didn't really help. Maybe it's a setup problem? My problem is, php is absolutely new to me, so I don't even know how to start diagnosing the problem (I started experimenting just a few hours ago). To decide whether it's a setup problem, here's the development platform: OS: Kubuntu 10.04.1 LTS Apache: Apache/2.2.14 (Ubuntu) PHP: 1.0.5-dev json version: 1.2.1 I don't think the browser is relevant, since it behaves the same in Opera and Firefox, and it doesn't happen in the browser, it happens on the server, since that's what wireshark shows. TIA, flj -- In politics, stupidity is not a handicap. (Napoleon) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Encodings - loose guidelines
Marc Guay wrote: 1.) Saving strings to a database One thing I always forget to remember is to send tge SET NAMES utf8 command to MySQL after making a connection. This will save you 1000 headaches if you're working with non-latin characters. I can't count the number of times I've thrown htmlentities, htmlspecialchars, utf8_encode/decode/, stripslashes, etc, etc around trying to figure out why those É's aren't being saved or read properly. I imagine this might fall into the category of best practice. Marc Thanks for the heads up! Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String Encodings - loose guidelines
Hello, I don't yet have a complete understanding of string encodings for the various environments they may need to pass through or be in. I have found bits and pieces within Larry's book, the online docs, and by googling... and my app seems to be working fine, but I don't yet feel confident on best practices. So, I thought I'd see if I could spark some feedback to the following: 1.) Saving strings to a database 2.) print/echo'ing string fields from a database. a. Allowing HTML? b. Not allowing HTML? 3.) print/echo'ing string fields into form textareas. 4.) Simply encoding strings to send over a GET request. 5.) Simply displaying strings from the $_REQUEST array. 6.) string encoding for redirects I understand that some of the above may depend on what database is being used. However, here is basically what I'm using successfully so far (disclaimer: obviously I am not sure of things here which is why I am asking the question ;-) ): 1.) $t_string = mysql_real_escape_string($f_varied_chars); //if using MySQL (optionally could use htmlspecialchars()?) to not allow html? 2.) print $db_string; a. Nothing different.. or perhaps htmlspecialchars_decode()? b. use htmlspecialchars upon saving to database, or using print htmlentities($db_string);?? 3.) textarea..?PHP print htmlspecialchars($db_string); ?/textarea? 4.) $t_string = urlencode($t_varied_chars); //(not sure if htmlentities would be needed in certain situations) a href=page.php?f_string=$t_stringx/a 5.) print urldecode($_GET['t_string']); //(not sure if html_entity_decode() would be needed in certain situations where you would want to display html?) 6.) ob_end_clean(); // destroy buffer $t_string = urlencode(text with varied chars); $t_url = page.php?f_string=$t_string; header (Location: $t_url); exit; TIA, Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Encodings - loose guidelines
1.) Saving strings to a database One thing I always forget to remember is to send tge SET NAMES utf8 command to MySQL after making a connection. This will save you 1000 headaches if you're working with non-latin characters. I can't count the number of times I've thrown htmlentities, htmlspecialchars, utf8_encode/decode/, stripslashes, etc, etc around trying to figure out why those É's aren't being saved or read properly. I imagine this might fall into the category of best practice. Marc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String passed to object constructor turning into aninstance of that object?
David Harkness wrote: I've never used the old-style constructors, but perhaps the semantics of parent:: changed and you need to instead use $this- as in $this-Tag(option, $name); That's a total guess. I don't have 5.2 handy to try it out, but both work in 5.3 using a simple example. Can you post the constructor of one of the Tag subclasses that work? Maybe we can find a common denominator. The most similar is Column, but all of them do very similar things - it's just the one class that seems to take a string and mutate it into what looks like an array with a string at [0] and something closely resembling what the whole object instance *should* be at [1]. class Table extends Tag { function Table() { parent::Tag('table'); $this-addAttribute('cellspacing', 0); $this-addAttribute('cellpadding', 0); $this-addAttribute('border', 0); $this-columns = array(); $this-rows = array(); } class Row extends Tag { function Row($table='') { parent::Tag('tr'); $this-table = ''; } class Column extends Tag { function Column($data) { parent::Tag('td', $data); $this-tagContent = $data; } class FormObject extends Tag { function FormObject($name='') { parent::Tag(); $this-addAttribute(name, $name); $this-name = $name; } -kgd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String passed to object constructor turning into aninstance of that object?
Nathan Nobbe wrote: 2. try modifying Tag SelectBoxOption to have __construct() instead of Tag() SelectBoxOption(), then call parent::__construct() from inside of SelectBoxOption::__construct(); see if that clears up your problem under 5.2 (read: this will only be a partial solution as it only addresses one child of Tag). Mmm. I hoped this would help, but all it seems to have done was cascade errors across the rest of Tag's object children. :( to be expected, but did it fix the problem w/ SelectBoxOption? I'm not sure, but I don't think so; the original symptom was Object of class SelectBoxOption could not be converted to string - the original code didn't include a toString() method in SelectBoxOption, and since the code works on an older PHP, it must be using the parent object's toString(). (Which some children of Tag do explicitly, but SelectBoxOption doesn't for whatever reason.) In trying to add the toString() method, I found that the calls used by other tags to retrieve the HTML tag name, value, etc weren't working. So I looked up at the constructor to see if the pieces passed in were getting passed and stored correctly - and quite obviously they're not ($name mutates into what looks like an array with a string at [0] and something closely resembling what the whole object instance *should* be at [1], and $value just seems to disappear). Putting aside actually fixing the constructor correctly, after a bit of poking I found that $this-tagContent-. works to retrieve the data and actually output the option tag correctly. var_dump tells me that the real data is actually in there... it's just not instantiated correctly. $name apparently arrives at the constructor for SelectOptionBox like this: string(8) Abegweit object(SelectBoxOption)#65 (5) { [attributes]= array(1) { [0]= object(TagAttribute)#66 (3) { [name]= string(5) value [value]= string(1) 4 [hasValue]= bool(true) } } [tagContent]= string(8) Abegweit [tag]= string(6) option [showEndTag]= bool(false) [children]= array(0) { } } I'll try converting all of the constructors to your recommendation as above, but given that the problem is only happening with this one class, I'm not sure that will do much. hopefully that clears it up .. Well, I ran out of Call to undefined ParentClass::parentclass in path/to/file/for/subclass.php errors (at least on the page I'm testing with) but $name is still going in on the calling side as a string, and coming out as a funky array. and hopefully you're using version control :D Bah! Real man never make mistaaake! ... ooops. g (I've got the live site, on the old server, as reference, plus the regular backups of that machine.) -kgd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String passed to object constructor turning into an instance of that object?
I'm in the process of migrating customer websites off an old legacy server that's pushing EOL, and starting to show hardware failures. One site is throwing errors on what, so far as I can tell, should be perfectly working code. The original code works fine on both CentOS 3 (PHP 4.3.2) and CentOS 4 (4.3.9); the new server is still a bit outdated (Debian etch plus some backports and updates from lenny; PHP 5.2.0). The site was designed by staff at a previous hosting company and uses a combination of the Fusebox app framework (which seems to work OK, after a few relatively minor fixes) and a custom OOP structure. I'm not really sure what the actual problem is, but I've reached the point where this: class SelectBoxOption extends Tag { function SelectBoxOption($name, $value, $selected=false) { parent::Tag(option, $name); $this-addAttribute(value, $value); if($selected) { $this-addAttribute(selected, '', false); } if ($name == ) { echo nbsp;nbsp;nbsp;missing name!br\n; } // else { print nbsp;nbsp;nbsp;name $namebr\n; } if ($value == ) { echo nbsp;nbsp;nbsp;missing value!br\n; } } will parse and execute, but: - the page will contain missing value! for each option in the select this is generating - it will *not* contain missing name! - the option tags in the final output don't have content or value (they should have both). If I uncomment that else, I get: adding option name1 with value1 name value1 Catchable fatal error: Object of class SelectBoxOption could not be converted to string in webroot/includes/classes/core/display/form/input/SelectBoxOption.php on line 12 I found the place this object is created, and added some debugging output before *and* after that call: echo adding option .$row-$nameField. with . $row-$valueField.br\n; $this-add(new SelectBoxOption($row-$nameField, $row-$valueField, $selected)); echo added option .$row-$nameField. with . $row-$valueField.br\n; which behaves correctly and spits out the name and value (retrieved from a database - thankfully I haven't had to track *that* down... yet). Can anyone explain why a string passed by value (apparently) would suddenly mutate into a SelectBoxOption object? I've confirmed that this is exactly what happens by adding this: if (is_a($name,'SelectBoxOption')) { print name isn't a SelectBoxOption, silly rabbit!br\n; } as the very next set of lines after function SelectBoxOption(. I wondered while typing this if $name and $value might have ended up as special variables somewhere, but renaming them with an opt_ prefix didn't change anything. -kgd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String passed to object constructor turning into an instance of that object?
-Original Message- From: Kris Deugau [mailto:kdeu...@vianet.ca] Sent: Thursday, December 16, 2010 11:57 AM To: php-general@lists.php.net Subject: [PHP] String passed to object constructor turning into an instance of that object? I'm in the process of migrating customer websites off an old legacy server that's pushing EOL, and starting to show hardware failures. One site is throwing errors on what, so far as I can tell, should be perfectly working code. The original code works fine on both CentOS 3 (PHP 4.3.2) and CentOS 4 (4.3.9); the new server is still a bit outdated (Debian etch plus some backports and updates from lenny; PHP 5.2.0). The site was designed by staff at a previous hosting company and uses a combination of the Fusebox app framework (which seems to work OK, after a few relatively minor fixes) and a custom OOP structure. I'm not really sure what the actual problem is, but I've reached the point where this: class SelectBoxOption extends Tag { function SelectBoxOption($name, $value, $selected=false) { parent::Tag(option, $name); $this-addAttribute(value, $value); if($selected) { $this-addAttribute(selected, '', false); } if ($name == ) { echo nbsp;nbsp;nbsp;missing name!br\n; } // else { print nbsp;nbsp;nbsp;name $namebr\n; } if ($value == ) { echo nbsp;nbsp;nbsp;missing value!br\n; } } will parse and execute, but: - the page will contain missing value! for each option in the select this is generating - it will *not* contain missing name! - the option tags in the final output don't have content or value (they should have both). If I uncomment that else, I get: adding option name1 with value1 name value1 Catchable fatal error: Object of class SelectBoxOption could not be converted to string in webroot/includes/classes/core/display/form/input/SelectBoxOption.php on line 12 What's the actual line #12 in the file SelectBoxOption.php? The SelectBoxOption code you presented has 11 lines unless it's a CNP error. Regards, Tommy I found the place this object is created, and added some debugging output before *and* after that call: echo adding option .$row-$nameField. with . $row-$valueField.br\n; $this-add(new SelectBoxOption($row-$nameField, $row-$valueField, $selected)); echo added option .$row-$nameField. with . $row-$valueField.br\n; which behaves correctly and spits out the name and value (retrieved from a database - thankfully I haven't had to track *that* down... yet). Can anyone explain why a string passed by value (apparently) would suddenly mutate into a SelectBoxOption object? I've confirmed that this is exactly what happens by adding this: if (is_a($name,'SelectBoxOption')) { print name isn't a SelectBoxOption, silly rabbit!br\n; } as the very next set of lines after function SelectBoxOption(. I wondered while typing this if $name and $value might have ended up as special variables somewhere, but renaming them with an opt_ prefix didn't change anything. -kgd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String passed to object constructor turning into an instance of that object?
Tommy Pham wrote: class SelectBoxOption extends Tag { function SelectBoxOption($name, $value, $selected=false) { parent::Tag(option, $name); $this-addAttribute(value, $value); if($selected) { $this-addAttribute(selected, '', false); } if ($name == ) { echo nbsp;nbsp;nbsp;missing name!br\n; } // else { print nbsp;nbsp;nbsp;name $namebr\n; } if ($value == ) { echo nbsp;nbsp;nbsp;missing value!br\n; } } will parse and execute, but: - the page will contain missing value! for each option in the select this is generating - it will *not* contain missing name! - the option tags in the final output don't have content or value (they should have both). If I uncomment that else, I get: adding option name1 with value1 name value1 Catchable fatal error: Object of class SelectBoxOption could not be converted to string in webroot/includes/classes/core/display/form/input/SelectBoxOption.php on line 12 What's the actual line #12 in the file SelectBoxOption.php? The SelectBoxOption code you presented has 11 lines unless it's a CNP error. Whups, thought I noted that. I trimmed a couple of blank lines; line 12 in the file is that print in the else. I found trying to print $name triggers the same error anywhere in that function, too; as I noted further down it seems the string that's passed in is getting mutated into an object. (Whose missing toString function is what led me here - but it works fine in PHP 4.3...) -kgd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String passed to object constructor turning into aninstance of that object?
Nathan Nobbe wrote: Why not test for the type of $name at each point of interest in the SelectBoxOption constructor? If you're passing a string value to the constructor it almost has to be getting changed by the Tag constructor, right ? class SelectBoxOption extends Tag { function SelectBoxOption($name, $value, $selected=false) { var_dump(is_string($name)); parent::Tag(option, $name); var_dump(is_string($name)); Ah, that gives... well, it slightly alters the confusion. Using var_dump(is_string($name)) gives... two results? bool(true) bool(false) And dumping $name itself gives: string(8) Abegweit object(SelectBoxOption)#65 (5) { [attributes]= array(1) { [0]= object(TagAttribute)#66 (3) { [name]= string(5) value [value]= string(1) 4 [hasValue]= bool(true) } } [tagContent]= string(8) Abegweit [tag]= string(6) option [showEndTag]= bool(false) [children]= array(0) { } } O_o Just to confirm, I checked a test instance of the site on CentOS 4, with PHP 4.3, and I get one bool(true) for each option - not two as is happening with PHP 5.2. -kgd (I haven't worked with PHP for quite a while, and I never really spent a lot of time getting deep into complex data structures and object hierarchies like this when I was using it. But this behaviour does NOT match what I know of passing values and object references around in any other language.) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String passed to object constructor turning into aninstance of that object?
On Thu, Dec 16, 2010 at 3:21 PM, Kris Deugau kdeu...@vianet.ca wrote: Nathan Nobbe wrote: Why not test for the type of $name at each point of interest in the SelectBoxOption constructor? If you're passing a string value to the constructor it almost has to be getting changed by the Tag constructor, right ? class SelectBoxOption extends Tag { function SelectBoxOption($name, $value, $selected=false) { var_dump(is_string($name)); parent::Tag(option, $name); var_dump(is_string($name)); Ah, that gives... well, it slightly alters the confusion. Using var_dump(is_string($name)) gives... two results? bool(true) bool(false) And dumping $name itself gives: string(8) Abegweit object(SelectBoxOption)#65 (5) { [attributes]= array(1) { [0]= object(TagAttribute)#66 (3) { [name]= string(5) value [value]= string(1) 4 [hasValue]= bool(true) } } [tagContent]= string(8) Abegweit [tag]= string(6) option [showEndTag]= bool(false) [children]= array(0) { } } O_o Just to confirm, I checked a test instance of the site on CentOS 4, with PHP 4.3, and I get one bool(true) for each option - not two as is happening with PHP 5.2. probly something screwy going on w/ the old style of naming constructors. 2 things, 1. can you post the Tag constructor as it reads now? 2. try modifying Tag SelectBoxOption to have __construct() instead of Tag() SelectBoxOption(), then call parent::__construct() from inside of SelectBoxOption::__construct(); see if that clears up your problem under 5.2 (read: this will only be a partial solution as it only addresses one child of Tag). -kgd (I haven't worked with PHP for quite a while, and I never really spent a lot of time getting deep into complex data structures and object hierarchies like this when I was using it. But this behaviour does NOT match what I know of passing values and object references around in any other language.) Probly because the term 'reference' in php means something rather different than it does in say java for example.
Re: [PHP] String passed to object constructor turning into aninstance of that object?
It's acting as if Tag's constructor a) declares $name as a reference using $name, and b) is assigning itself ($this) to $name for some (probably bad) reason. That's the only way I can see that $name inside SelectBoxOption's constructor could change from a string to an object. A peek at Tag's constructor could really clear things up. David
Re: [PHP] String passed to object constructor turning into an instance of that object?
Nathan Nobbe wrote: probly something screwy going on w/ the old style of naming constructors. 2 things, 1. can you post the Tag constructor as it reads now? function Tag($tag='', $tagContent='') { $this-tagContent = $tagContent; $this-tag = $tag; $this-showEndTag = false; $this-attributes = array(); $this-children = array(); } 2. try modifying Tag SelectBoxOption to have __construct() instead of Tag() SelectBoxOption(), then call parent::__construct() from inside of SelectBoxOption::__construct(); see if that clears up your problem under 5.2 (read: this will only be a partial solution as it only addresses one child of Tag). Mmm. I hoped this would help, but all it seems to have done was cascade errors across the rest of Tag's object children. :( Copying the old constructor back in resolved that, but I'm not sure whether that reintroduces the root problem. Other objects derived from Tag seem to work just fine; I came into this chunk of the code trying to find out why a SelectBoxOption didn't seem to have a toString function - and then why trying to access what should be the value and name the same way as with other objects derived at some level from Tag blew up instead of working happily. I'll try converting all of the constructors to your recommendation as above, but given that the problem is only happening with this one class, I'm not sure that will do much. (A don't-break-crusty-old-code option for php.ini would be handy...) The class hierarchy I've dug up so far looks like this (and appears to have been entirely defined by the original developer): Object Fieldset RadioButtonGroup Tag Column FormObject FormInput CheckBox DateSelector Editor FileField FormButton HiddenField PasswordField RadioButton SelectBox PopulatedSelectBox RecursiveSelectBox TextArea TextField Form Row Table SelectBoxOption -kgd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String passed to object constructor turning into an instance of that object?
On Thu, Dec 16, 2010 at 4:04 PM, Kris Deugau kdeu...@vianet.ca wrote: Nathan Nobbe wrote: probly something screwy going on w/ the old style of naming constructors. 2 things, 1. can you post the Tag constructor as it reads now? function Tag($tag='', $tagContent='') { $this-tagContent = $tagContent; $this-tag = $tag; $this-showEndTag = false; $this-attributes = array(); $this-children = array(); } seems innocuous .. 2. try modifying Tag SelectBoxOption to have __construct() instead of Tag() SelectBoxOption(), then call parent::__construct() from inside of SelectBoxOption::__construct(); see if that clears up your problem under 5.2 (read: this will only be a partial solution as it only addresses one child of Tag). Mmm. I hoped this would help, but all it seems to have done was cascade errors across the rest of Tag's object children. :( to be expected, but did it fix the problem w/ SelectBoxOption? Copying the old constructor back in resolved that, but I'm not sure whether that reintroduces the root problem. Other objects derived from Tag seem to work just fine; I came into this chunk of the code trying to find out why a SelectBoxOption didn't seem to have a toString function - and then why trying to access what should be the value and name the same way as with other objects derived at some level from Tag blew up instead of working happily. I'll try converting all of the constructors to your recommendation as above, but given that the problem is only happening with this one class, I'm not sure that will do much. hopefully that clears it up .. and hopefully you're using version control :D -nathan
Re: [PHP] String passed to object constructor turning into an instance of that object?
I've never used the old-style constructors, but perhaps the semantics of parent:: changed and you need to instead use $this- as in $this-Tag(option, $name); That's a total guess. I don't have 5.2 handy to try it out, but both work in 5.3 using a simple example. Can you post the constructor of one of the Tag subclasses that work? Maybe we can find a common denominator. David
Re: [PHP] String passed to object constructor turning into aninstance of that object?
On Thu, Dec 16, 2010 at 3:21 PM, Kris Deugau kdeu...@vianet.ca wrote: Nathan Nobbe wrote: Why not test for the type of $name at each point of interest in the SelectBoxOption constructor? If you're passing a string value to the constructor it almost has to be getting changed by the Tag constructor, right ? class SelectBoxOption extends Tag { function SelectBoxOption($name, $value, $selected=false) { var_dump(is_string($name)); parent::Tag(option, $name); var_dump(is_string($name)); Ah, that gives... well, it slightly alters the confusion. Using var_dump(is_string($name)) gives... two results? bool(true) bool(false) so you put one check before the call to parent::Tag() one directly after right? That means *somehow* $name is getting set to an instance of SelectBoxOption in the parent constructor which makes little to no sense.. especially after looking at implementation from your later post. Main things are $name is local in the child constructor and there is no pass by reference on the $name parameter in the parent constructor definition. if this code runs w/o error on your 5.2 box, then there's something spurious going on in that old library; ?php class Tag { function Tag($sTag='', $sValue='') { $this-_sTag = $sTag; $this-_sValue = $sValue; } } class Child extends Tag { function Child($name) { var_dump($name); parent::Tag('option', $name); var_dump($name); } } $oChild = new Child('content'); ? expected output: string(7) content string(7) content I'd still recommend moving to the php5 notation throughout the library, especially if doing that fixes the problem w/ SelectBoxOption. This shouldn't break any client code, since clients should all be calling new Class() and not be explicitly invoking the php4 style constructors. The php4 style constructors should only be getting called explicitly from within the library itself. -nathan
Re: [PHP] String Parse Help for novice
At 9:29 PM -0400 6/13/10, Robert Cummings wrote: ?php function my_parse_url( $url ) { $parsed = parse_url( $url ); $parsed['file'] = basename( $parsed['path'] ); $parsed['pathbits'] = explode( '/', ltrim( dirname( $parsed['path'] ), '/' ) ); return $parsed; } $url = my_parse_url( 'http://foo.fee.com/blah/bleh/bluh/meh.php' ); print_r( $url ); ? Cheers, Rob. Rob: Very neat. It also handles url's like this: http://mydomain.com/mydirectory/mysubdirectory/anothersubdirectory/mypage.php See Demo here: http://www.webbytedd.com/b4/parse-url/index.php Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
tedd wrote: At 9:29 PM -0400 6/13/10, Robert Cummings wrote: ?php function my_parse_url( $url ) { $parsed = parse_url( $url ); $parsed['file'] = basename( $parsed['path'] ); $parsed['pathbits'] = explode( '/', ltrim( dirname( $parsed['path'] ), '/' ) ); return $parsed; } $url = my_parse_url( 'http://foo.fee.com/blah/bleh/bluh/meh.php' ); print_r( $url ); ? Cheers, Rob. Rob: Very neat. It also handles url's like this: http://mydomain.com/mydirectory/mysubdirectory/anothersubdirectory/mypage.php See Demo here: http://www.webbytedd.com/b4/parse-url/index.php It's useful to leverage the work of others. So using parse_url() gets you all the parsing stuff for a url without having to worry about the spec (such as embedded user, password, port, parameters, and fragment. Then we just augment to provide the extra functionality :) 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
[PHP] String Parse Help for novice
Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] String Parse Help for novice
On Jun 13, 2010, at 5:13 PM, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi Rick, Just a thought, but cant you do something to separate them according to the / (forward slash)? maybe preg_replace or something. Sorry not much more help. Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk Hi Ash, What about the // in the beginning? Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
On Sun, 2010-06-13 at 17:27 -0500, Karl DeSaulniers wrote: On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk Hi Ash, What about the // in the beginning? Karl DeSaulniers Design Drumm http://designdrumm.com As your example string didn't have a double slash I didn't write code for that, but it's easy enough to remove 0-length strings from the $directories array. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] String Parse Help for novice
On Jun 13, 2010, at 5:31 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 17:27 -0500, Karl DeSaulniers wrote: On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk Hi Ash, What about the // in the beginning? Karl DeSaulniers Design Drumm http://designdrumm.com As your example string didn't have a double slash I didn't write code for that, but it's easy enough to remove 0-length strings from the $directories array. Thanks, Ash http://www.ashleysheridan.co.uk :) Rick's example, but how in your example do we look for a double forward slash? THX Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
OK, I get the following error: Warning: basename() expects parameter 1 to be string, array given in When I use the following: $thepath = parse_url($url); $filename = basename($thepath); Is my variable thepath not automatically string? --Rick On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
On Jun 13, 2010, at 5:35 PM, Rick Dwyer wrote: OK, I get the following error: Warning: basename() expects parameter 1 to be string, array given in When I use the following: $thepath = parse_url($url); $filename = basename($thepath); Is my variable thepath not automatically string? --Rick try echo($url); and see Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
On Sun, 2010-06-13 at 17:35 -0500, Karl DeSaulniers wrote: On Jun 13, 2010, at 5:31 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 17:27 -0500, Karl DeSaulniers wrote: On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk Hi Ash, What about the // in the beginning? Karl DeSaulniers Design Drumm http://designdrumm.com As your example string didn't have a double slash I didn't write code for that, but it's easy enough to remove 0-length strings from the $directories array. Thanks, Ash http://www.ashleysheridan.co.uk :) Rick's example, but how in your example do we look for a double forward slash? THX Karl DeSaulniers Design Drumm http://designdrumm.com You don't look for one, that's the point. The explode() breaks the string into an array at every occurrence of a '/' character. This will leave zero length strings in the array if there is a double // (which wasn't in any given example in this thread that I saw) When you use the array, just don't do anything with empty elements! Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] String Parse Help for novice
On Jun 13, 2010, at 5:35 PM, Rick Dwyer wrote: OK, I get the following error: Warning: basename() expects parameter 1 to be string, array given in When I use the following: $thepath = parse_url($url); $filename = basename($thepath); Is my variable thepath not automatically string? --Rick Oops I meant echo($the_path); or echo both and see. Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
On Sun, 2010-06-13 at 18:35 -0400, Rick Dwyer wrote: OK, I get the following error: Warning: basename() expects parameter 1 to be string, array given in When I use the following: $thepath = parse_url($url); $filename = basename($thepath); Is my variable thepath not automatically string? --Rick On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk Because you've given it an array. Your original question never mentioned you were using parse_url() on the original array string. parse_url() breaks the string into its component parts, much like my explode example. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] String Parse Help for novice
On Jun 13, 2010, at 5:40 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 17:35 -0500, Karl DeSaulniers wrote: On Jun 13, 2010, at 5:31 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 17:27 -0500, Karl DeSaulniers wrote: On Jun 13, 2010, at 5:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk Hi Ash, What about the // in the beginning? Karl DeSaulniers Design Drumm http://designdrumm.com As your example string didn't have a double slash I didn't write code for that, but it's easy enough to remove 0-length strings from the $directories array. Thanks, Ash http://www.ashleysheridan.co.uk :) Rick's example, but how in your example do we look for a double forward slash? THX Karl DeSaulniers Design Drumm http://designdrumm.com You don't look for one, that's the point. The explode() breaks the string into an array at every occurrence of a '/' character. This will leave zero length strings in the array if there is a double // (which wasn't in any given example in this thread that I saw) When you use the array, just don't do anything with empty elements! Thanks, Ash http://www.ashleysheridan.co.uk Ahh.. that makes sense. Thanks Ash. Karl DeSaulniers Design Drumm http://designdrumm.com
Re: [PHP] String Parse Help for novice
OK, sorry for any confusion. Here is all my code: $url = http . ((!empty($_SERVER['HTTPS'])) ? s : ) . ://. $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $thepath = parse_url($url); So, given that the URL can vary as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. --Rick On Jun 13, 2010, at 6:42 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:35 -0400, Rick Dwyer wrote: OK, I get the following error: Warning: basename() expects parameter 1 to be string, array given in When I use the following: $thepath = parse_url($url); $filename = basename($thepath); Is my variable thepath not automatically string? --Rick On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk Because you've given it an array. Your original question never mentioned you were using parse_url() on the original array string. parse_url() breaks the string into its component parts, much like my explode example. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Parse Help for novice
On Sun, 2010-06-13 at 18:52 -0400, Rick Dwyer wrote: OK, sorry for any confusion. Here is all my code: $url = http . ((!empty($_SERVER['HTTPS'])) ? s : ) . ://. $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $thepath = parse_url($url); So, given that the URL can vary as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. --Rick On Jun 13, 2010, at 6:42 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:35 -0400, Rick Dwyer wrote: OK, I get the following error: Warning: basename() expects parameter 1 to be string, array given in When I use the following: $thepath = parse_url($url); $filename = basename($thepath); Is my variable thepath not automatically string? --Rick On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote: On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. --Rick $filename = basename($path); $parts = explode('/', $path); $directories = array_pop($parts); Now you have your directories in the $directories array and the filename in $filename. Thanks, Ash http://www.ashleysheridan.co.uk Because you've given it an array. Your original question never mentioned you were using parse_url() on the original array string. parse_url() breaks the string into its component parts, much like my explode example. Thanks, Ash http://www.ashleysheridan.co.uk Take out the parse_url line and use the code I gave you, or keep the parse_url line and drop my explode line. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] String Parse Help for novice
Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. ?php function my_parse_url( $url ) { $parsed = parse_url( $url ); $parsed['file'] = basename( $parsed['path'] ); $parsed['pathbits'] = explode( '/', ltrim( dirname( $parsed['path'] ), '/' ) ); return $parsed; } $url = my_parse_url( 'http://foo.fee.com/blah/bleh/bluh/meh.php' ); print_r( $url ); ? 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] String Parse Help for novice
On Sun, Jun 13, 2010 at 9:29 PM, Robert Cummings rob...@interjinn.comwrote: Rick Dwyer wrote: Hello List. I need to parse the PATH portion of URL. I have assigned the path portion to a variable using the following: $thepath = parse_url($url); Now I need to break each portion of the path down into its own variable. The problem is, the path can vary considerably as follows: /mydirectory/mysubdirectory/anothersubdirectory/mypage.php vs. /mydirectory/mypage.php How do I get the either of the above url paths broken out so the variables equal the following $dir1 = mydirectory $dir2 = mysubdirectory $dir3 = anothersubdirectory $page = mypage.php ...etc... if there were 5 more subdirectories... they would be dynamically assigned to a variable. Thanks for any help. ?php function my_parse_url( $url ) { $parsed = parse_url( $url ); $parsed['file'] = basename( $parsed['path'] ); $parsed['pathbits'] = explode( '/', ltrim( dirname( $parsed['path'] ), '/' ) ); return $parsed; } $url = my_parse_url( 'http://foo.fee.com/blah/bleh/bluh/meh.php' ); print_r( $url ); ? 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 Clean and lean, Robert ;) Nice! Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP] php string syntax question with html
On Thu, 2010-03-11 at 08:03 +0100, Rene Veerman wrote: $var = 'bla'.$var2.'doh'.$var3['index'].'argh'.$var4[$var4index]; is so much more readable in any editor that does syntax highlighting, and parses quicker too. On Thu, Mar 11, 2010 at 1:15 AM, David Mehler dave.meh...@gmail.com wrote: Hello, I've got what is probably a very simple question, probably something having to do with quotes single vs. double, but the answer is frustrating elusive, I keep getting a syntax error. I'm trying to customize a wordpress theme a friend sent me. We're both using apache as web server and php5, but his has got to be configed differently than mine. The theme deals with multiple stylesheet inclusion among other things. The original line is: $styleSheets[0][sheet]='link href=/wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; That code puts the link in the head portion of the document. The issue is his / is not where mine is, i'm using a virtual host and need a line similar to this: $styleSheets[0][sheet]='link href=$_SERVER['DOCUMENT_ROOT'] . /wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; I've tried this with both double quotes before the link declaration, but keep getting a parse error. Help appreciated. Thanks. Dave. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Good catch Paul with the quotes around the array element! My editor highlights those strings even without me having to keep breaking out with concatenation Rene Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] php string syntax question with html
Ah, ok.. Turns out mine does too ;) So for light apps, it can be considered a coder's preference then.. On Thu, Mar 11, 2010 at 9:16 AM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: My editor highlights those strings even without me having to keep breaking out with concatenation Rene
[PHP] php string syntax question with html
Hello, I've got what is probably a very simple question, probably something having to do with quotes single vs. double, but the answer is frustrating elusive, I keep getting a syntax error. I'm trying to customize a wordpress theme a friend sent me. We're both using apache as web server and php5, but his has got to be configed differently than mine. The theme deals with multiple stylesheet inclusion among other things. The original line is: $styleSheets[0][sheet]='link href=/wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; That code puts the link in the head portion of the document. The issue is his / is not where mine is, i'm using a virtual host and need a line similar to this: $styleSheets[0][sheet]='link href=$_SERVER['DOCUMENT_ROOT'] . /wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; I've tried this with both double quotes before the link declaration, but keep getting a parse error. Help appreciated. Thanks. Dave. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php string syntax question with html
Try this: 'link href='.$_SERVER['DOCUMENT_ROOT'] .'/wp-content/themes/themestyle/white.css rel=stylesheet type=text/css /'; On Wed, Mar 10, 2010 at 7:15 PM, David Mehler dave.meh...@gmail.com wrote: Hello, I've got what is probably a very simple question, probably something having to do with quotes single vs. double, but the answer is frustrating elusive, I keep getting a syntax error. I'm trying to customize a wordpress theme a friend sent me. We're both using apache as web server and php5, but his has got to be configed differently than mine. The theme deals with multiple stylesheet inclusion among other things. The original line is: $styleSheets[0][sheet]='link href=/wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; That code puts the link in the head portion of the document. The issue is his / is not where mine is, i'm using a virtual host and need a line similar to this: $styleSheets[0][sheet]='link href=$_SERVER['DOCUMENT_ROOT'] . /wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; I've tried this with both double quotes before the link declaration, but keep getting a parse error. Help appreciated. Thanks. Dave. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP] php string syntax question with html
On Wed, 2010-03-10 at 19:33 -0500, Adam Richardson wrote: Try this: 'link href='.$_SERVER['DOCUMENT_ROOT'] .'/wp-content/themes/themestyle/white.css rel=stylesheet type=text/css /'; On Wed, Mar 10, 2010 at 7:15 PM, David Mehler dave.meh...@gmail.com wrote: Hello, I've got what is probably a very simple question, probably something having to do with quotes single vs. double, but the answer is frustrating elusive, I keep getting a syntax error. I'm trying to customize a wordpress theme a friend sent me. We're both using apache as web server and php5, but his has got to be configed differently than mine. The theme deals with multiple stylesheet inclusion among other things. The original line is: $styleSheets[0][sheet]='link href=/wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; That code puts the link in the head portion of the document. The issue is his / is not where mine is, i'm using a virtual host and need a line similar to this: $styleSheets[0][sheet]='link href=$_SERVER['DOCUMENT_ROOT'] . /wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; I've tried this with both double quotes before the link declaration, but keep getting a parse error. Help appreciated. Thanks. Dave. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You're using single quotes in your string, so you can't have PHP parse the string for variables to extend into their corresponding values. If you wish to do that, use either double-quoted strings or heredoc/nowdoc syntax: $styleSheets[0][sheet]=link href= \{$_SERVER['DOCUMENT_ROOT']}/wp-content/themes/theme/style/white.css\ rel=\stylesheet\ type=\text/css\ /; or $styleSheets[0][sheet]= EOS link href={$_SERVER['DOCUMENT_ROOT']}/wp-content/themes/theme/style/white.css rel=stylesheet type=text/css / EOS; In both cases note the {} surrounding the variable. This is because PHP needs to be told that you are trying to access an array element, otherwise it will match only as far as $_SERVER and think that the [ character starts regular text. This also works with object properties and method return values: echo {$some_obect-some_value} and {$some_object-some_method()}; Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] php string syntax question with html
On Thu, Mar 11, 2010 at 01:17:57AM +, Ashley Sheridan wrote: snip You're using single quotes in your string, so you can't have PHP parse the string for variables to extend into their corresponding values. If you wish to do that, use either double-quoted strings or heredoc/nowdoc syntax: $styleSheets[0][sheet]=link href= \{$_SERVER['DOCUMENT_ROOT']}/wp-content/themes/theme/style/white.css\ rel=\stylesheet\ type=\text/css\ /; or $styleSheets[0][sheet]= EOS link href={$_SERVER['DOCUMENT_ROOT']}/wp-content/themes/theme/style/white.css rel=stylesheet type=text/css / EOS; In both cases note the {} surrounding the variable. This is because PHP needs to be told that you are trying to access an array element, otherwise it will match only as far as $_SERVER and think that the [ character starts regular text. This also works with object properties and method return values: echo {$some_obect-some_value} and {$some_object-some_method()}; Um, not exactly. This will parse correctly: $_SERVER[DOCUMENT_ROOT]. You just can't use single quotes inside the brackets to denote the array index, when the whole string is surrounded by double quotes. A more pedestrian example: $message = The value of foo is $_POST[bar]\n; You are, however, right about object properties. I know of no other way to parse them inside a quoted string, other than using braces. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php string syntax question with html
$var = 'bla'.$var2.'doh'.$var3['index'].'argh'.$var4[$var4index]; is so much more readable in any editor that does syntax highlighting, and parses quicker too. On Thu, Mar 11, 2010 at 1:15 AM, David Mehler dave.meh...@gmail.com wrote: Hello, I've got what is probably a very simple question, probably something having to do with quotes single vs. double, but the answer is frustrating elusive, I keep getting a syntax error. I'm trying to customize a wordpress theme a friend sent me. We're both using apache as web server and php5, but his has got to be configed differently than mine. The theme deals with multiple stylesheet inclusion among other things. The original line is: $styleSheets[0][sheet]='link href=/wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; That code puts the link in the head portion of the document. The issue is his / is not where mine is, i'm using a virtual host and need a line similar to this: $styleSheets[0][sheet]='link href=$_SERVER['DOCUMENT_ROOT'] . /wp-content/themes/theme/style/white.css rel=stylesheet type=text/css /'; I've tried this with both double quotes before the link declaration, but keep getting a parse error. Help appreciated. Thanks. Dave. -- 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] string concatenation with fgets
aurfal...@gmail.com wrote: So here is my final test code, notice the check for ' ' in the if. Since I'm on Linux, this has to do with whats between the last LF and EOF which is nothing but this nothing will get printed out. $file = fopen(somefile.txt, r); while (! feof($file)) { $tmp = trim(fgets($file)); if ($tmp != '') { $names = $tmp; } print $names.sometext\n; } fclose($file); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation with fgets
Hi Shawn, Your code looks cleaner then mine so i tried it and got the last entry in the txt file printed twice. On Nov 30, 2009, at 7:07 AM, Shawn McKenzie wrote: aurfal...@gmail.com wrote: So here is my final test code, notice the check for ' ' in the if. Since I'm on Linux, this has to do with whats between the last LF and EOF which is nothing but this nothing will get printed out. $file = fopen(somefile.txt, r); while (! feof($file)) { $tmp = trim(fgets($file)); if ($tmp != '') { $names = $tmp; } print $names.sometext\n; } fclose($file); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation with fgets
On Mon, 2009-11-30 at 09:04 -0800, aurfal...@gmail.com wrote: Hi Shawn, Your code looks cleaner then mine so i tried it and got the last entry in the txt file printed twice. On Nov 30, 2009, at 7:07 AM, Shawn McKenzie wrote: aurfal...@gmail.com wrote: So here is my final test code, notice the check for ' ' in the if. Since I'm on Linux, this has to do with whats between the last LF and EOF which is nothing but this nothing will get printed out. $file = fopen(somefile.txt, r); while (! feof($file)) { $tmp = trim(fgets($file)); if ($tmp != '') { $names = $tmp; } print $names.sometext\n; } fclose($file); -- Thanks! -Shawn http://www.spidean.com Remove the if statement and just print out $tmp. The while loop is going over one extra time than you need, and on that final iteration, $tmp is an empty string. The if statement only changes $name if $tmp is empty, so it leaves it as it was, hence you getting the last line printed twice. Printing out an empty string in this example won't do anything, and the if statement is also pretty useless as it just copies the value to another variable on a condition that will only result in the side-effect you've noticed. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] string concatenation with fgets
Hi Ash, Actually I need the if because the code will print out an empty line and add sometext to it. So without the if check for an empty line, at the end of the loop I'll get sometext. For example, if the file I am processing called somename.txt has a b c in it. I'll have; asometext bsometext csometext but w/o the if check, I'll also have sometext as well. On Nov 30, 2009, at 9:24 AM, Ashley Sheridan wrote: On Mon, 2009-11-30 at 09:04 -0800, aurfal...@gmail.com wrote: Hi Shawn, Your code looks cleaner then mine so i tried it and got the last entry in the txt file printed twice. On Nov 30, 2009, at 7:07 AM, Shawn McKenzie wrote: aurfal...@gmail.com wrote: So here is my final test code, notice the check for ' ' in the if. Since I'm on Linux, this has to do with whats between the last LF and EOF which is nothing but this nothing will get printed out. $file = fopen(somefile.txt, r); while (! feof($file)) { $tmp = trim(fgets($file)); if ($tmp != '') { $names = $tmp; } print $names.sometext\n; } fclose($file); -- Thanks! -Shawn http://www.spidean.com Remove the if statement and just print out $tmp. The while loop is going over one extra time than you need, and on that final iteration, $tmp is an empty string. The if statement only changes $name if $tmp is empty, so it leaves it as it was, hence you getting the last line printed twice. Printing out an empty string in this example won't do anything, and the if statement is also pretty useless as it just copies the value to another variable on a condition that will only result in the side-effect you've noticed. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] string concatenation with fgets
On Mon, 2009-11-30 at 09:40 -0800, aurfal...@gmail.com wrote: Hi Ash, Actually I need the if because the code will print out an empty line and add sometext to it. So without the if check for an empty line, at the end of the loop I'll get sometext. For example, if the file I am processing called somename.txt has a b c in it. I'll have; asometext bsometext csometext but w/o the if check, I'll also have sometext as well. On Nov 30, 2009, at 9:24 AM, Ashley Sheridan wrote: On Mon, 2009-11-30 at 09:04 -0800, aurfal...@gmail.com wrote: Hi Shawn, Your code looks cleaner then mine so i tried it and got the last entry in the txt file printed twice. On Nov 30, 2009, at 7:07 AM, Shawn McKenzie wrote: aurfal...@gmail.com wrote: So here is my final test code, notice the check for ' ' in the if. Since I'm on Linux, this has to do with whats between the last LF and EOF which is nothing but this nothing will get printed out. $file = fopen(somefile.txt, r); while (! feof($file)) { $tmp = trim(fgets($file)); if ($tmp != '') { $names = $tmp; } print $names.sometext\n; } fclose($file); -- Thanks! -Shawn http://www.spidean.com Remove the if statement and just print out $tmp. The while loop is going over one extra time than you need, and on that final iteration, $tmp is an empty string. The if statement only changes $name if $tmp is empty, so it leaves it as it was, hence you getting the last line printed twice. Printing out an empty string in this example won't do anything, and the if statement is also pretty useless as it just copies the value to another variable on a condition that will only result in the side-effect you've noticed. Thanks, Ash http://www.ashleysheridan.co.uk Then put the print statement inside the if, not the assignation, otherwise you will always get that last line! Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] string concatenation with fgets
So here is my final test code, notice the check for ' ' in the if. Since I'm on Linux, this has to do with whats between the last LF and EOF which is nothing but this nothing will get printed out. $file = fopen(somefile.txt, r); while (! feof($file)) { $names = trim(fgets($file)); if ($names == '') { break; } print $names.sometext\n; } fclose($file); - aurf On Nov 24, 2009, at 5:52 PM, ryan wrote: Is this what you want $file = fopen(test.txt, r); while (!feof($file)) { $line = trim(fgets($file)); print $line.sometext\n; } fclose($file); outputs asometext bsometext csometext Ref to http://us3.php.net/manual/en/function.fgets.php. Reading ends when /length/ - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. aurfal...@gmail.com wrote: Hi all, I'm trying to append some text to what I read from a file. My code; $file = fopen(foo.txt, r); while (!feof($file)) { $line = fgets($file); print $line.sometext; } fclose($file); foo,txt; a b c d e f g And when I run the script, it looks like; a sometextb sometextc sometextd ... Any ideas? Thanks in advance, - aurf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] string concatenation with fgets
Hi all, I'm trying to append some text to what I read from a file. My code; $file = fopen(foo.txt, r); while (!feof($file)) { $line = fgets($file); print $line.sometext; } fclose($file); foo,txt; a b c d e f g And when I run the script, it looks like; a sometextb sometextc sometextd ... Any ideas? Thanks in advance, - aurf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation with fgets
Is this what you want $file = fopen(test.txt, r); while (!feof($file)) { $line = trim(fgets($file)); print $line.sometext\n; } fclose($file); outputs asometext bsometext csometext Ref to http://us3.php.net/manual/en/function.fgets.php. Reading ends when /length/ - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. aurfal...@gmail.com wrote: Hi all, I'm trying to append some text to what I read from a file. My code; $file = fopen(foo.txt, r); while (!feof($file)) { $line = fgets($file); print $line.sometext; } fclose($file); foo,txt; a b c d e f g And when I run the script, it looks like; a sometextb sometextc sometextd ... Any ideas? Thanks in advance, - aurf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation with fgets
--- On Wed, 11/25/09, aurfal...@gmail.com aurfal...@gmail.com wrote: From: aurfal...@gmail.com aurfal...@gmail.com Subject: [PHP] string concatenation with fgets To: php-general@lists.php.net Date: Wednesday, November 25, 2009, 7:00 AM Hi all, I'm trying to append some text to what I read from a file. My code; $file = fopen(foo.txt, r); while (!feof($file)) { $line = fgets($file); print $line.sometext; } fclose($file); foo,txt; a b c d e f g And when I run the script, it looks like; a sometextb sometextc sometextd ... Any ideas? So, what output you actually wants from your program? Is it like this asometextbsometextcsometext.. or, like this asometext bsometext csometext --- নির্মাল্য লাহিড়ী [Nirmalya Lahiri] +৯১-৯৪৩৩১১৩৫৩৬ [+91-9433113536] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation with fgets
On Nov 24, 2009, at 5:55 PM, Nirmalya Lahiri wrote: --- On Wed, 11/25/09, aurfal...@gmail.com aurfal...@gmail.com wrote: From: aurfal...@gmail.com aurfal...@gmail.com Subject: [PHP] string concatenation with fgets To: php-general@lists.php.net Date: Wednesday, November 25, 2009, 7:00 AM Hi all, I'm trying to append some text to what I read from a file. My code; $file = fopen(foo.txt, r); while (!feof($file)) { $line = fgets($file); print $line.sometext; } fclose($file); foo,txt; a b c d e f g And when I run the script, it looks like; a sometextb sometextc sometextd ... Any ideas? So, what output you actually wants from your program? Is it like this asometextbsometextcsometext.. or, like this asometext bsometext csometext Hi, Sorry, I was incomplete :) I would like; asometext bsometext csometext Basically, I would like to add whatever text to the end of what I find in the file. So if the file contains a b c I would like; asometext bsometext csometext... - aurf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string concatenation with fgets
On Nov 24, 2009, at 5:52 PM, ryan wrote: Is this what you want $file = fopen(test.txt, r); while (!feof($file)) { $line = trim(fgets($file)); print $line.sometext\n; } fclose($file); outputs asometext bsometext csometext Ref to http://us3.php.net/manual/en/function.fgets.php. Reading ends when /length/ - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. aurfal...@gmail.com wrote: Hi all, I'm trying to append some text to what I read from a file. My code; $file = fopen(foo.txt, r); while (!feof($file)) { $line = fgets($file); print $line.sometext; } fclose($file); foo,txt; a b c d e f g And when I run the script, it looks like; a sometextb sometextc sometextd ... Any ideas? Thanks in advance, - aurf OMG, very very cool, thanks Ryan. - aurf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP String convention
Nick Cooper wrote: Hi, I was just wondering what the difference/advantage of these two methods of writing a string are: 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 1) breaks PHPUnit when used in classes (need to bug report that) 2) [concatenation] is faster (but you wouldn't notice) comes down to personal preference and what looks best in your (teams) IDE I guess; legibility (and possibly portability) is probably the primary concern. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP String convention
2009/10/28 Warren Vail war...@vailtech.net: The curly braces look like something from the smarty template engine. Warren Vail Odd. I always thought the curly braces in the Smarty engine looked like something from PHP. :) Torben -Original Message- From: Kim Madsen [mailto:php@emax.dk] Sent: Wednesday, October 28, 2009 10:18 AM To: Nick Cooper Cc: Jim Lucas; php-general@lists.php.net Subject: Re: [PHP] PHP String convention Hi Nick Nick Cooper wrote on 2009-10-28 17:29: Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? Yes, you're right about that. 10 years ago I went to a seminar were Rasmus Lerforf was speaking and asked him exactly that question. The single qoutes are preferred and are way faster because it doesn´t have to parse the string, only the glued variables. Also we discussed that if you´re doing a bunch of HTML code it's considerably faster to do: tr td?= $data ?/td /tr Than print \n\ttr \n\t\ttd$data/td \n\t/tr; or print ' tr td'.$data.'/td /tr'; I remember benchmark testing it afterwards back then and there was clearly a difference. -- Kind regards Kim Emax - masterminds.dk -- 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] Re: PHP String convention
2009/11/4 Nathan Rixham nrix...@gmail.com: Nick Cooper wrote: Hi, I was just wondering what the difference/advantage of these two methods of writing a string are: 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 1) breaks PHPUnit when used in classes (need to bug report that) 2) [concatenation] is faster (but you wouldn't notice) comes down to personal preference and what looks best in your (teams) IDE I guess; legibility (and possibly portability) is probably the primary concern. I would tend to agree here; the concat is faster but you may well only notice in very tight loops. The curly brace syntax can increase code readability, depending on the complexity of the expression. I use them both depending on the situation. Remember the rules of optimization: 1) Don't. 2) (Advanced users only): Optimize later. Write code so that it's readable, and then once it's working, identify the bottlenecks and optimize where needed. If you understand code analysis and big-O etc then you will start to automatically write mostly-optimized code anyway and in general, I doubt that you'll often identify the use of double quotes as a bottleneck--it almost always turns out that other operations and code structures are far more expensive and impact code speed much more. That said, you don't really lose anything by using concatenation from the start, except perhaps some legibility, so as Nathan said it often really just comes down to personal preference and perhaps the house coding conventions. Regards, Torben 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] PHP String convention
Hi, I was just wondering what the difference/advantage of these two methods of writing a string are: 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; I always use method 2 but have been noticing method 1 more and more in source code. Is this just user preference? I would use a generic search engine but not sure what the first method is called so don't know where to begin my search. Thanks for any help. Nick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP String convention
[snip]I was just wondering what the difference/advantage of these two methods of writing a string are:[/snip] Method 2 is faster, YMMV. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP String convention
Nick Cooper wrote: Hi, I was just wondering what the difference/advantage of these two methods of writing a string are: 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; I always use method 2 but have been noticing method 1 more and more in source code. Is this just user preference? I would use a generic search engine but not sure what the first method is called so don't know where to begin my search. Thanks for any help. Nick I think it is a matter of personal preference. I prefer method 1 myself. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP String convention
2009/10/28 Jim Lucas: Nick Cooper wrote: Hi, I was just wondering what the difference/advantage of these two methods of writing a string are: 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; I always use method 2 but have been noticing method 1 more and more in source code. Is this just user preference? I would use a generic search engine but not sure what the first method is called so don't know where to begin my search. Thanks for any help. Nick I think it is a matter of personal preference. I prefer method 1 myself. Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP String convention
On Wed, 2009-10-28 at 16:29 +, Nick Cooper wrote: 2009/10/28 Jim Lucas: Nick Cooper wrote: Hi, I was just wondering what the difference/advantage of these two methods of writing a string are: 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; I always use method 2 but have been noticing method 1 more and more in source code. Is this just user preference? I would use a generic search engine but not sure what the first method is called so don't know where to begin my search. Thanks for any help. Nick I think it is a matter of personal preference. I prefer method 1 myself. Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? This was on the list a few days back. Basically, the braces are there to force PHP to recognise the full variable name, so that you could type: $string = {$foo}bar; $string = foo{$bar[0][1]}; $string = {$foo-bar}; Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] PHP String convention
Nick Cooper wrote: 2009/10/28 Jim Lucas: Nick Cooper wrote: Hi, I was just wondering what the difference/advantage of these two methods of writing a string are: 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; I always use method 2 but have been noticing method 1 more and more in source code. Is this just user preference? I would use a generic search engine but not sure what the first method is called so don't know where to begin my search. Thanks for any help. Nick I think it is a matter of personal preference. I prefer method 1 myself. Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? They tell PHP to view the text between the curly braces as a variable that needs interpreting. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP String convention
Hi Nick Nick Cooper wrote on 2009-10-28 17:29: Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? Yes, you're right about that. 10 years ago I went to a seminar were Rasmus Lerforf was speaking and asked him exactly that question. The single qoutes are preferred and are way faster because it doesn´t have to parse the string, only the glued variables. Also we discussed that if you´re doing a bunch of HTML code it's considerably faster to do: tr td?= $data ?/td /tr Than print \n\ttr \n\t\ttd$data/td \n\t/tr; or print ' tr td'.$data.'/td /tr'; I remember benchmark testing it afterwards back then and there was clearly a difference. -- Kind regards Kim Emax - masterminds.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP String convention
The curly braces look like something from the smarty template engine. Warren Vail -Original Message- From: Kim Madsen [mailto:php@emax.dk] Sent: Wednesday, October 28, 2009 10:18 AM To: Nick Cooper Cc: Jim Lucas; php-general@lists.php.net Subject: Re: [PHP] PHP String convention Hi Nick Nick Cooper wrote on 2009-10-28 17:29: Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? Yes, you're right about that. 10 years ago I went to a seminar were Rasmus Lerforf was speaking and asked him exactly that question. The single qoutes are preferred and are way faster because it doesn´t have to parse the string, only the glued variables. Also we discussed that if you´re doing a bunch of HTML code it's considerably faster to do: tr td?= $data ?/td /tr Than print \n\ttr \n\t\ttd$data/td \n\t/tr; or print ' tr td'.$data.'/td /tr'; I remember benchmark testing it afterwards back then and there was clearly a difference. -- Kind regards Kim Emax - masterminds.dk -- 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] PHP String convention
On Wed, 2009-10-28 at 18:18 +0100, Kim Madsen wrote: Hi Nick Nick Cooper wrote on 2009-10-28 17:29: Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? Yes, you're right about that. 10 years ago I went to a seminar were Rasmus Lerforf was speaking and asked him exactly that question. The single qoutes are preferred and are way faster because it doesn´t have to parse the string, only the glued variables. Also we discussed that if you´re doing a bunch of HTML code it's considerably faster to do: tr td?= $data ?/td /tr Than print \n\ttr \n\t\ttd$data/td \n\t/tr; or print ' tr td'.$data.'/td /tr'; I remember benchmark testing it afterwards back then and there was clearly a difference. -- Kind regards Kim Emax - masterminds.dk Or, far easier still to do: print EOC tr td$data/td /tr tr td$data/td /tr EOC; than: tr td?= $data ?/td /tr tr td?= $data ?/td /tr Also, the use of short tags in the second example will almost certainly cause problems later on if you want to do anything with XML output from PHP. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP String convention
Kim Madsen wrote: Hi Nick Nick Cooper wrote on 2009-10-28 17:29: Thank you for the quick replies. I thought method 2 must be faster because it doesn't have to search for variables in the string. So what is the advantages then of method 1 over 3, do the curly braces mean anything? 1) $string = foo{$bar}; 2) $string = 'foo'.$bar; 3) $string = foo$bar; I must admit reading method 1 is easier, but writing method 2 is quicker, is that the only purpose the curly braces serve? Yes, you're right about that. 10 years ago I went to a seminar were Rasmus Lerforf was speaking and asked him exactly that question. The single qoutes are preferred and are way faster because it doesn´t have to parse the string, only the glued variables. Also we discussed that if you´re doing a bunch of HTML code it's considerably faster to do: tr td?= $data ?/td /tr Than print \n\ttr \n\t\ttd$data/td \n\t/tr; or print ' tr td'.$data.'/td /tr'; I remember benchmark testing it afterwards back then and there was clearly a difference. 10 years is a long time... there have been benchmarks posted to this list in the past year or so indicating that in the PHP5 release there is no real difference in speed between the use of single or double quotes. If I recall correctly double quotes may even be eking out a small advantage over single quotes nowadays. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String scrambling
!niBgo /* $str = Bingo!; str_shuffle($str); */ :)
Re: [PHP] String scrambling
On Fri, 2009-09-11 at 11:03 +0100, Tom Chubb wrote: !niBgo /* $str = Bingo!; str_shuffle($str); */ :) No, that won't work at all, it's in comments ;) Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String scrambling
On Thu, Sep 10, 2009 at 8:57 PM, Ron Piggott ron@actsministries.org wrote: Is there a function in PHP which scrambles strings? Example: $string = Hello; Output might be: ehlol Ron http://www.php.net/manual/en/function.str-shuffle.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String Formulas
How can I take a mathematical formula that is in a string and have the result, product, sum, etc. returned? I did a search on the Web and couldn't find any suitable solutions. Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String to Date Conversion Problem
Hi, Guys: I am trying to turn a prepared line into a date format, and the string looks something like this: 23 JUL 09 - THURSDAY, and I am trying to change the string to a mm/dd/ format that looks like 07/23/2009. I tried to use strtotime() but it gave me nothing. Here is the code: list($date,$month,$year,$dash,$day) = split( ,$line,5); echo date2 . strtotime($date . \s . $month . \s . $year). /date2; Could anyone on the list please give me a hint on what I might have done wrong here? Thanks for your help. Alice _ All-in-one security and maintenance for your PC. Get a free 90-day trial! http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail
Re: [PHP] String to Date Conversion Problem
Hi Alice, Based on the string format that you mentioned (DD MMM YY - DAY) you should be able to transform to any other date using the following: $parts = explode(' ', '23 JUL 09 - THURSDAY'); echo date('m/d/Y', strtotime({$parts[1]} {$parts[0]} {$parts[2]})); Cheers Stuart On 31 Jul 2009, at 15:19, Alice Wei wrote: Hi, Guys: I am trying to turn a prepared line into a date format, and the string looks something like this: 23 JUL 09 - THURSDAY, and I am trying to change the string to a mm/dd/ format that looks like 07/23/2009. I tried to use strtotime() but it gave me nothing. Here is the code: list($date,$month,$year,$dash,$day) = split( ,$line,5); echo date2 . strtotime($date . \s . $month . \s . $year). /date2; Could anyone on the list please give me a hint on what I might have done wrong here? Thanks for your help. Alice _ All-in-one security and maintenance for your PC. Get a free 90-day trial! http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail smime.p7s Description: S/MIME cryptographic signature
RE: [PHP] String to Date Conversion Problem
Looks like what I did by using mm/dd/ was extra, which was probably why it didn't work. Thanks, looks like this is up and running now. Alice CC: php-general@lists.php.net From: stu...@stuconnolly.com To: aj...@alumni.iu.edu Subject: Re: [PHP] String to Date Conversion Problem Date: Fri, 31 Jul 2009 15:45:44 +0100 Hi Alice, Based on the string format that you mentioned (DD MMM YY - DAY) you should be able to transform to any other date using the following: $parts = explode(' ', '23 JUL 09 - THURSDAY'); echo date('m/d/Y', strtotime({$parts[1]} {$parts[0]} {$parts[2]})); Cheers Stuart On 31 Jul 2009, at 15:19, Alice Wei wrote: Hi, Guys: I am trying to turn a prepared line into a date format, and the string looks something like this: 23 JUL 09 - THURSDAY, and I am trying to change the string to a mm/dd/ format that looks like 07/23/2009. I tried to use strtotime() but it gave me nothing. Here is the code: list($date,$month,$year,$dash,$day) = split( ,$line,5); echo date2 . strtotime($date . \s . $month . \s . $year). /date2; Could anyone on the list please give me a hint on what I might have done wrong here? Thanks for your help. Alice _ All-in-one security and maintenance for your PC. Get a free 90-day trial! http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us
Re: [PHP] String variable
On Sun, Jan 11, 2009 at 8:59 AM, MikeP mpel...@princeton.edu wrote: Hello, I am trying yo get THIS: where ref_id = '1234' from this. $where=where ref_id=.'$Reference[$x][ref_id]'; but i certainly have a quote problem. Any help? Thanks Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Looks like you're missing the single tics around ref_id. In your example you'd want one of these: $where=where ref_id=.'{$Reference[$x]['ref_id']}; $where=where ref_id=.$Reference[$x]['ref_id']; $where=sprintf(where ref_id=%d, (int)$Reference[$x]['ref_id']); -- use this one or else! (sql injection) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String variable
On Sun, 2009-01-11 at 08:59 -0500, MikeP wrote: Hello, I am trying yo get THIS: where ref_id = '1234' from this. $where=where ref_id=.'$Reference[$x][ref_id]'; but i certainly have a quote problem. Any help? Thanks Mike It should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String variable
On Sun, 2009-01-11 at 14:36 +, Ashley Sheridan wrote: On Sun, 2009-01-11 at 08:59 -0500, MikeP wrote: Hello, I am trying yo get THIS: where ref_id = '1234' from this. $where=where ref_id=.'$Reference[$x][ref_id]'; but i certainly have a quote problem. Any help? Thanks Mike It should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; Ash www.ashleysheridan.co.uk Sorry, it should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; I missed taking an extra quote mark out Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String variable
Ashley Sheridan wrote: On Sun, 2009-01-11 at 14:36 +, Ashley Sheridan wrote: On Sun, 2009-01-11 at 08:59 -0500, MikeP wrote: Hello, I am trying yo get THIS: where ref_id = '1234' from this. $where=where ref_id=.'$Reference[$x][ref_id]'; but i certainly have a quote problem. Any help? Thanks Mike It should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; Ash www.ashleysheridan.co.uk Sorry, it should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; I missed taking an extra quote mark out Ash www.ashleysheridan.co.uk actually unless ref_id is a constant (which i doublt) you may be best going with: $where = WHERE ref_id=' . $Reference[$x]['ref_id'] . '; keep the php and sql seperate and you'll find it much easier to see in you're editor (imho) :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String variable
2009/1/11 Ashley Sheridan a...@ashleysheridan.co.uk: On Sun, 2009-01-11 at 14:36 +, Ashley Sheridan wrote: On Sun, 2009-01-11 at 08:59 -0500, MikeP wrote: Hello, I am trying yo get THIS: where ref_id = '1234' from this. $where=where ref_id=.'$Reference[$x][ref_id]'; but i certainly have a quote problem. Any help? Thanks Mike It should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; Ash www.ashleysheridan.co.uk Sorry, it should look like this: $where=where ref_id='{$Reference[$x][ref_id]}'; I missed taking an extra quote mark out Closer, but still not quite there. For encapsulation in the string, it should look like: $where = where ref_is='{$Reference[$x]['ref_id']}'; Someone else mentioned casting to int first as well to sanitize, which is also a good idea. Torben Ash www.ashleysheridan.co.uk -- Torben Wilson tor...@2powerweb.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] string comparison
hi i am writing a small application where a user enters a phrase in the textfield and i would like to display all the files present in the root directory which consists of the keyword or keywords entered by the user. i have used a few comparison functions but i am not getting the expected result. $my_file = file_get_contents(filename.html); what ever the user enters whether it is a single word or few words i would like to compare with $my_file in a case insensitive manner. can anyone suggest the best method and how to go about. thanks.
Re: [PHP] string comparison
On Sun, 2008-07-13 at 21:47 +0530, Sudhakar wrote: hi i am writing a small application where a user enters a phrase in the textfield and i would like to display all the files present in the root directory which consists of the keyword or keywords entered by the user. i have used a few comparison functions but i am not getting the expected result. $my_file = file_get_contents(filename.html); what ever the user enters whether it is a single word or few words i would like to compare with $my_file in a case insensitive manner. can anyone suggest the best method and how to go about. I don't suggest using file_get_contents. It would probably be more efficient (at least less memory intensive) to use fopen() and fread(). Just be sure you overlap each read by $the_size_of_the_largest phrase_or_keyword - 1. Then use stripos() for matching... of course that won't work so well if whitespace doesn't need to match exactly in phrases. In which case you'll need to resort to other techniques. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string comparison
On Jul 13, 2008, at 9:17 AM, Sudhakar wrote: hi i am writing a small application where a user enters a phrase in the textfield and i would like to display all the files present in the root directory which consists of the keyword or keywords entered by the user. i have used a few comparison functions but i am not getting the expected result. I use this script to list archive files from a directory based on keyword. I'd guess a modified version using the keywords from users might work: // create archives box if ($handle = opendir('../diaryarchives/')) { while (false !== ($file = readdir($handle))) { $pos = strpos($file, diary_); $pagemarked = diary._; if ($pos !== false) { //print $filebr; $file_name = ereg_replace ($pagemarked,,$file); $file_name = ereg_replace (.php,,$file_name); //print * $file_namebr; //print $filebr; $archive_list_gather[] = 'lia href=/diaryarchives/'. $file.''.$file_name.'/a/li'; } } closedir($handle); } rsort($archive_list_gather); foreach($archive_list_gather as $value) { $archive_list .= $value; } // build archives box $archives_box = 'div id=diary-archives h3 class=sideimg src=/images/h3s_diaryarchives.gif alt=Diary Archives width=225 height=20 //h3 ul '.$archive_list.' /ul /div'; // publish archives box $filename = PATHA.'/diaryarchivesbox.php'; publishpages($archives_box, $filename); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String to date
I need to convert a date retrieved from user input to a mysql date. Here the problem, I need to convert one of three possible combinations, either 01/01/2008,01-01-2008 or 01.01.2008. I can't use explode because it's limited to one character to explode on. I would prefer not to use regexp, but think I am going to have to. The one part of the code that works below is using 01/01/2008 format. Any suggestions echo $olddate = '06/06/2008'; echo br /; echo $olddate2 = '06-16-2008'; echo br /; echo $olddate3 = '06.26.2008'; echo br /; echo $newdate = date(Y-m-d,strtotime($olddate)); echo br /; echo $newdate2 = date(Y-m-d,strtotime($olddate2)); echo br /; echo $newdate3 = date(Y-m-d,strtotime($olddate3)); markb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String to date
On Mon, Jun 30, 2008 at 4:58 PM, Mark Bomgardner [EMAIL PROTECTED] wrote: I need to convert a date retrieved from user input to a mysql date. Here the problem, I need to convert one of three possible combinations, either 01/01/2008,01-01-2008 or 01.01.2008. I can't use explode because it's limited to one character to explode on. I would prefer not to use regexp, but think I am going to have to. The one part of the code that works below is using 01/01/2008 format. Any suggestions echo $olddate = '06/06/2008'; echo br /; echo $olddate2 = '06-16-2008'; echo br /; echo $olddate3 = '06.26.2008'; echo br /; echo $newdate = date(Y-m-d,strtotime($olddate)); echo br /; echo $newdate2 = date(Y-m-d,strtotime($olddate2)); echo br /; echo $newdate3 = date(Y-m-d,strtotime($olddate3)); markb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Your date field should always be the same in the database. The just use the date function to format that date when displaying to the user...don't alter the date format as it may make the date field unusable for queries or throw errors when attempting to insert. -- Bastien Cat, the other other white meat
Re: [PHP] String to date
Mark Bomgardner [EMAIL PROTECTED] wrote: I need to convert a date retrieved from user input to a mysql date. Here the problem, I need to convert one of three possible combinations, either 01/01/2008,01-01-2008 or 01.01.2008. I can't use explode because it's limited to one character to explode on. I would prefer not to use regexp, but think I am going to have to. The one part of the code that works below is using 01/01/2008 format. Any suggestions echo $olddate = '06/06/2008'; echo br /; echo $olddate2 = '06-16-2008'; echo br /; echo $olddate3 = '06.26.2008'; echo br /; echo $newdate = date(Y-m-d,strtotime($olddate)); echo br /; echo $newdate2 = date(Y-m-d,strtotime($olddate2)); echo br /; echo $newdate3 = date(Y-m-d,strtotime($olddate3)); markb You've given us no code you are actually using (we can all write dummy test code). IMO, you need to either change your input form to give you the results in a certain way (split up the M,D,Y or only accept it in a specific format or any other way) OR You run the strpos and look for / . or - or or ? and then use the data on that field. Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String to date
-Original Message- From: Mark Bomgardner [mailto:[EMAIL PROTECTED] Sent: Monday, June 30, 2008 3:58 PM To: php-general@lists.php.net Subject: [PHP] String to date I need to convert a date retrieved from user input to a mysql date. Here the problem, I need to convert one of three possible combinations, either 01/01/2008,01-01-2008 or 01.01.2008. I can't use explode because it's limited to one character to explode on. I would prefer not to use regexp, but think I am going to have to. The one part of the code that works below is using 01/01/2008 format. Any suggestions echo $olddate = '06/06/2008'; echo br /; echo $olddate2 = '06-16-2008'; echo br /; echo $olddate3 = '06.26.2008'; echo br /; echo $newdate = date(Y-m-d,strtotime($olddate)); echo br /; echo $newdate2 = date(Y-m-d,strtotime($olddate2)); echo br /; echo $newdate3 = date(Y-m-d,strtotime($olddate3)); Step 1.) Replace all - with /. Step 2.) Replace all . with /. Step 3.) Err.. wait.. you're done. Todd Boyd Web Programmer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String to date
couldn't strtotime() do this without any mods? I personally would try that first... On 6/30/08, Mark Bomgardner [EMAIL PROTECTED] wrote: I need to convert a date retrieved from user input to a mysql date. Here the problem, I need to convert one of three possible combinations, either 01/01/2008,01-01-2008 or 01.01.2008. I can't use explode because it's limited to one character to explode on. I would prefer not to use regexp, but think I am going to have to. The one part of the code that works below is using 01/01/2008 format. Any suggestions echo $olddate = '06/06/2008'; echo br /; echo $olddate2 = '06-16-2008'; echo br /; echo $olddate3 = '06.26.2008'; echo br /; echo $newdate = date(Y-m-d,strtotime($olddate)); echo br /; echo $newdate2 = date(Y-m-d,strtotime($olddate2)); echo br /; echo $newdate3 = date(Y-m-d,strtotime($olddate3)); markb -- 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] String searching
I need to find the position of the first character in the string (searching from the end) that is not one of the characters in a set. In this case the set is [0-9a-zA-z-_] I guess to be even more specific, I want to split a string into to parts the first part can contain anything and the second part must be only in the set described above. What is the easiest way to do this? -- Chris W KE5GIX Protect your digital freedom and privacy, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm; Ham Radio Repeater Database. http://hrrdb.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String searching
On Sat, May 17, 2008 at 2:17 AM, Chris W [EMAIL PROTECTED] wrote: I need to find the position of the first character in the string (searching from the end) that is not one of the characters in a set. In this case the set is [0-9a-zA-z-_] To find the position of a specific character, RTFM on strpos(). For those not existing in your condition, I'd recommend everythingbut(), but it's yet to be included in the core. ;-P I guess to be even more specific, I want to split a string into to parts the first part can contain anything and the second part must be only in the set described above. You can split a string by doing something as simple as this: ?php $str = abcdefghijklmnopqrstuvwxyz; $d = $str[5]; // $d == position - 1, because count always begins with 0 ? So to walk backward through the string, while it's not very clean, you could do: ?php $str = ABCDEF01234567789; for($i=strlen($str);$i0;$i--) { if(preg_match('/[g-z]/i',$str[$i])) { // Handle your this is a bad character condition(s). // break; /* Or, optionally, continue. */ } } ? Not pretty, but if my mind is still working at 2:30a (EDT), it should help you out. -- /Daniel P. Brown Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String searching
Chris W wrote: I need to find the position of the first character in the string (searching from the end) that is not one of the characters in a set. In this case the set is [0-9a-zA-z-_] I guess to be even more specific, I want to split a string into to parts the first part can contain anything and the second part must be only in the set described above. What is the easiest way to do this? There's something here, imaginatively called blah(), which does what you require: http://www.phpguru.org/preg/example.phps -- Richard Heyes ++ | Access SSH with a Windows mapped drive | |http://www.phpguru.org/sftpdrive| ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string
John Taylor-Johnston wrote: $name = John Taylor; I want to verify if $name contains john, if yes echo found; Cannot remember which to use: http://ca.php.net/manual/en/ref.strings.php Either http://php.net/strpos or http://php.net/stripos if your version of PHP supports it. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] string
$name = John Taylor; I want to verify if $name contains john, if yes echo found; Cannot remember which to use: http://ca.php.net/manual/en/ref.strings.php Sorry, John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RES: [PHP] string
?php $name = John Taylor; if (strpos($name,'John') 0){ //you could use stripos for case insensitive search echo found; } ? -Mensagem original- De: John Taylor-Johnston [mailto:[EMAIL PROTECTED] Enviada em: segunda-feira, 7 de abril de 2008 10:25 Para: PHP-General Assunto: [PHP] string $name = John Taylor; I want to verify if $name contains john, if yes echo found; Cannot remember which to use: http://ca.php.net/manual/en/ref.strings.php Sorry, John -- 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] string
Do a preg match to find one or preg_match_all to find all the john in the string. ?php $name = John Taylor; $pattern = '/^John/'; preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3); print_r($matches); ? $name = John Taylor; I want to verify if $name contains john, if yes echo found; Cannot remember which to use: http://ca.php.net/manual/en/ref.strings.php Sorry, John -- 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: RES: [PHP] string
Thiago Pojda wrote: ?php $name = John Taylor; if (strpos($name,'John') 0){ //you could use stripos for case insensitive search echo found; } ? This will not do what you expect it to. Since 'John' is the first thing in the string strpos will return 0 causing the condition to evaluate to false. As per the documentation for strpos you should compare the value *and type* of the variable returned by strpos against false to check for non-existance. if (strpos($name, 'John') !== false) { ... } -Stut -- http://stut.net/ -Mensagem original- De: John Taylor-Johnston [mailto:[EMAIL PROTECTED] Enviada em: segunda-feira, 7 de abril de 2008 10:25 Para: PHP-General Assunto: [PHP] string $name = John Taylor; I want to verify if $name contains john, if yes echo found; Cannot remember which to use: http://ca.php.net/manual/en/ref.strings.php Sorry, John -- 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
RES: RES: [PHP] string
Never late to learn new stuff, you're right Stut. Thanks! -Mensagem original- De: Stut [mailto:[EMAIL PROTECTED] Enviada em: segunda-feira, 7 de abril de 2008 10:42 Para: Thiago Pojda Cc: 'John Taylor-Johnston'; 'PHP-General' Assunto: Re: RES: [PHP] string Thiago Pojda wrote: ?php $name = John Taylor; if (strpos($name,'John') 0){ //you could use stripos for case insensitive search echo found; } ? This will not do what you expect it to. Since 'John' is the first thing in the string strpos will return 0 causing the condition to evaluate to false. As per the documentation for strpos you should compare the value *and type* of the variable returned by strpos against false to check for non-existance. if (strpos($name, 'John') !== false) { ... } -Stut -- http://stut.net/ -Mensagem original- De: John Taylor-Johnston [mailto:[EMAIL PROTECTED] Enviada em: segunda-feira, 7 de abril de 2008 10:25 Para: PHP-General Assunto: [PHP] string $name = John Taylor; I want to verify if $name contains john, if yes echo found; Cannot remember which to use: http://ca.php.net/manual/en/ref.strings.php Sorry, John -- 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