Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Community Answers

  1. NotionCommotion's post in Curl Request Append Response was marked as the answer   
    Okay, $textAr includes URLs for www.google.com\r and www.yahoo.com.  Do you really want the \r with Google?
    Then I see $line: www.google.com being echoed, but don't see the results being echoed.  Replace print_r with var_dump as it likely is returning NULL.
    Then I see $line: www.yahoo.com followed by the error message.  I would have expected a line break but not a big deal.
    Then I see the $results array with the first element being empty and the second being the error response.
    Isn't this what you were expecting?  Consider changing $result[] = $r; to $result[$line] = $r; to make it more clear.
  2. NotionCommotion's post in Troubleshooting Segmentation fault was marked as the answer   
    As seen by the first line of my original post, I am using a debugger dbg-php-7.1.so.  Disabled it, and now I see:  Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes).  Okay, not quite the mystery anymore.
  3. NotionCommotion's post in Validate a stdClass object against a blueprint or prototype was marked as the answer   
    I am sure it can be improved, but for what it is worth, this is what I will be doing.
    <?php function validate($input,$blueprint,$level='base',$errors=[]){     /*Only validates types string, integer, double and boolean, object (stdClass only), and arrays but not resources.     Arrays can not contain other arrays or objects, and all elements in the arrays must be of the same type     Objects are validated by specifying an associated array for the object's attribute name and attribute type.     */ if(!is_object($input)) return ['validate method must be passed an object'];     $input=(array) $input;     if($missing=array_diff_key($blueprint,$input)) {         $errors[]="'$level' object is missing properties '".implode(', ',array_flip($missing))."'.";     }     foreach($input as $prop=>$value){         if(empty($blueprint[$prop])) $errors[]="Unexpected property '$prop' provided in the '$level' object.";         else {             $type=gettype($value);             $typDesired=$blueprint[$prop];             if(gettype($blueprint[$prop])=='array') {                 $isAssoc=$blueprint[$prop]===[]?false:array_keys($blueprint[$prop]) !== range(0, count($blueprint[$prop]) - 1);                 $typDesired=$isAssoc?'object':'array';             }             if( $type!=$typDesired) $errors[]="Property '$prop' in the '$level' object is a $type but should be a $typDesired.";             elseif($type=='object') $errors=validate($value,$blueprint[$prop],"$level.$prop",$errors);             elseif($type=='array') {                 foreach($value as $item) {                     if( gettype($item)!=$blueprint[$prop][0]) {                         $errors[]="At least one element of the '$prop' array in the '$level' object has the incorrect type and all must be a ".$blueprint[$prop][0].'.';                         break;                     }                 }             }         }     }     return $errors; } $json='{"method":"maintenance.Tshark","params":{"paramString":" --guid d6f23460-0d77-400e-ae96-13f436e40245 --upload-server-ip --upload-server-port 22 --upload-server-user bacnet --params -f \'port 1337 or port 47808\' -i eth0 -a duration:5"},"extra":{"name":"filename","test":[1,4,7]}}'; $data=json_decode($json); $blueprint=['method'=>'string','params'=>['paramString'=>'stringx'],'extra'=>['nasme'=>'string','test'=>['string']]]; echo('<pre>'.print_r(validate($data,$blueprint),1).'</pre>'); Array (     [0] => Property 'paramString' in the 'base.params' object is a string but should be a stringx.     [1] => 'base.extra' object is missing properties 'nasme'.     [2] => Unexpected property 'name' provided in the 'base.extra' object.     [3] => At least one element of the 'test' array in the 'base.extra' object has the incorrect type and all must be a string. )
  4. NotionCommotion's post in Can't open sqlite db was marked as the answer   
    What a difference a space makes!
    $x=new PDO('sqlite:db.sqlite3');
  5. NotionCommotion's post in Help! Parse error: syntax error, unexpected was marked as the answer   
    Your missing your trailing semicolon. Ps. You don’t need one in your query.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.