Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Wednesday, May 28, 2014

PHP: NotORM tutorial

fatfree: error routing about in tutorial

following this tutorial : http://fatfreeframework.com/routing-engine, after adding

$f3->route('GET /about','WebPage->display');

the url localhost/myproject/ works fine, but localhost/myproject/about doesnt work.

To solve the problem, follow these steps:

1. create a file name .htaccess with the following content:

# Enable rewrite engine and route requests to framework
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]

# Disable ETags
<IfModule mod_headers.c>
Header Unset ETag
FileETag none
</IfModule>

# Default expires header if none specified (stay in browser cache for 7 days)
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A604800
</IfModule>

2. put the .htaccess file in the root of wour project, ie {apacheserverdir}\htdocs\pyproject\.htaccess

The error happens because is missing the .htaccess file in the right place:

\htdocs\myproject
\htdocs\myproject\.htaccess -- add htaccess file here
\htdocs\myproject\index.php
\htdocs\myproject\libs
\htdocs\myproject\libs\fatfree-master
......
\htdocs\myproject\libs\fatfree-master\.htaccess -- here is a htaccess file that is not used at all
......
\htdocs\myproject\libs\fatfree-master\lib
\htdocs\myproject\libs\fatfree-master\lib\audit.php
\htdocs\myproject\libs\fatfree-master\lib\auth.php
\htdocs\myproject\libs\fatfree-master\lib\base.php
......
......
.....

Resource:
https://github.com/bcosca/fatfree/blob/archive/f3-2.1.0-blog.example.zip

Friday, October 19, 2012

PHP: Unable to load dynamic library 'php_oci8.dll' , the procedure entry point ocilobread2 could not be located

Situation:

The Apache service wasn't starting

in the Apache error.log file I was getting the following error:

"Warning: PHP Startup: Unable to load dynamic library 'C:/php/ext/php_oci8.dll' - The specified procedure could not be found. \r \n in Unknown on line 0"

the I tried to execute from windows console the php command and I got the following error in an emerging window:

"the procedure entry point ocilobread2 could not be located in the dynamic link library oci.dll"

And also, in the PHP console, I got the error that I mentioned in the beginning of this post : "... Unable to load dynamic library .... "

Solution:

- download and unzip instantclient_10_2

- set PATH variable with the instantclient_10_2 folder route ie (C:\instantclient_10_2) . Note: Is VERY important that the instantclient path must be added at beginning of PATH variable or VERIFY the PATH variable in order to avoid having other routes to a different instanclient.

- check up php command in console

- restart APACHE


Resource:

https://forums.oracle.com/forums/thread.jspa?messageID=2324855

http://ivoronline.com/Coding/Languages/PHP/Tutorials/PHP%20-%20Errors%20-%20The%20specified%20procedure%20could%20not%20be%20found.php



Wednesday, October 3, 2012

Wednesday, July 25, 2012

PHP: decode HTML special Chars


<?php
$str = "<p>this -&gt; &quot;</p>\n";


echo htmlspecialchars_decode($str); // <p>this -> "</p>


// note that here the quotes aren't converted
echo htmlspecialchars_decode($str, ENT_NOQUOTES); // <p>this -> &quot;</p>
?>


Reference:
http://php.net/manual/en/function.htmlspecialchars-decode.php

Saturday, July 14, 2012

PHP: get keys from array

Use array_keys() method:

$array = array("color" => "blue", "size"  => "small");
print_r(array_keys($array)); /* prints the following:
Array
(
    [0] => color
    [1] => size
)*/

Reference:
http://php.net/manual/en/function.array-keys.php


Friday, July 13, 2012

PHP: split string by multiple delimiters


Use preg_split() method:

$pattern = '/[;,]/'; //regex
$string = "something here ; and there, oh,that's all!";
$myArray = preg_split( $pattern, $string );


Reference:
http://stackoverflow.com/questions/1452777/how-to-split-a-string-by-multiple-delimiters-in-php

PHP: get string length

$str = 'abcdef';
echo strlen($str); // 6


Resource:
http://php.net/manual/es/function.strlen.php

PHP: Capture var_dump into string


Using output buffering:

<?php
ob_start();
var_dump($someVar);
$result = ob_get_clean();
?>


Resource:
http://stackoverflow.com/questions/139474/how-can-i-capture-the-result-of-var-dump-to-a-string

Thursday, July 12, 2012

PHP: substring

Use substr method:

$myString = "0123456789"
// substr( string_wanna_substring , initial position(0-index),quantity-of-digits-wanna-take);             
// the var is $myString, the init position is 3 (0-index) so it beings from number 3, take 3 chars beginning with 3 so the //final result is 345
$mySubString = substr( $myString ,3,3); // 345


Reference:
http://php.net/manual/es/function.substr.php

PHP: get the type of a variable

use gettype method:


$var1 = "Hello";
gettype($var1); // String


Reference:
http://php.net/manual/es/function.gettype.php

Tuesday, July 10, 2012

PHP: static method

class Foo {
    public static function aStaticMethod() {
        // ...
    }
}
Foo::aStaticMethod();

Resource:
http://php.net/manual/es/language.oop5.static.php

PHP: find key into array


Use the in_array() method:


$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
    echo "Got Irix";
}
if (in_array("mac", $os)) {
    echo "Got mac";
}

Resource:
http://php.net/manual/en/function.in-array.php

PHP: simple array

$array = array(1, 2, 3, 4, 5);

Resource:
http://php.net/manual/es/language.types.array.php