echo mktime($hour,$minute,$second,$month,$day,$year);
sábado, 11 de abril de 2015
PHP substr() and explode
<?php
$time="2015/04/10 00:40";
echo substr($time,0,10); //Imprime los primeros 10 caracteres
echo "<br>";
echo substr($time,-6); //imprie los ultimos 6
?>
2015/04/10
00:40
<?php
$date="2015/04/11 15:20";
//$time=mktime($hour,$minute,$second,$month,$day,$year);
$time = explode("/",$date);
echo $time[0]." Year";
echo "<br>";
echo $time[1]." Month";
echo "<br>";
echo $time[2]." Day Hour minute";
echo "<br>";
echo substr($time[2],0,2)." Day";
echo "<br>";
echo substr($time[2],-2)." minutes";
echo "<br>";
echo substr($time[2],3,2)." Hour";
?>
2015 Year
04 Month
11 15:20 Day Hour minute
11 Day
20 minutes
15 Hour
$time="2015/04/10 00:40";
echo substr($time,0,10); //Imprime los primeros 10 caracteres
echo "<br>";
echo substr($time,-6); //imprie los ultimos 6
?>
2015/04/10
00:40
<?php
$date="2015/04/11 15:20";
//$time=mktime($hour,$minute,$second,$month,$day,$year);
$time = explode("/",$date);
echo $time[0]." Year";
echo "<br>";
echo $time[1]." Month";
echo "<br>";
echo $time[2]." Day Hour minute";
echo "<br>";
echo substr($time[2],0,2)." Day";
echo "<br>";
echo substr($time[2],-2)." minutes";
echo "<br>";
echo substr($time[2],3,2)." Hour";
?>
2015 Year
04 Month
11 15:20 Day Hour minute
11 Day
20 minutes
15 Hour
PHP Warning: date():
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone
How to fixed
/etc/php5/apache2/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone =America/Puerto_Rico
service apache2 restart
How to fixed
/etc/php5/apache2/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone =America/Puerto_Rico
service apache2 restart
lunes, 6 de abril de 2015
How to convert text to MP3 speech/Voice using Google API
<?php
include 'PHP_Text2Speech.class.php';
$t2s = new PHP_Text2Speech;
?>
<audio controls="controls" autoplay="autoplay">
<source src="<?php echo $t2s->speak("Hello PHPGang");?>" type="audio/mp3" />
</audio>
<?php
include 'PHP_Text2Speech.class.php';
$t2s = new PHP_Text2Speech;
?>
<audio controls="controls" autoplay="autoplay">
<source src="<?php echo $t2s->speak("Hello PHPGang");?>" type="audio/mp3" />
</audio>
1
2
3
|
if (!file_exists($this->mp3File)) {
$this->download("http://translate.google.com/translate_tts?ie=UTF-8&q={$this->text}&tl={$this->lang}&total={$this->wordCount}&idx=0&textlen={$this->textLen}", $this->mp3File);
}
|
?> | http://www.phpgang.com/how-to-convert-text-to-mp3-voice_284.html |
domingo, 5 de abril de 2015
PHP: Using functions/expressions in HEREDOC strings
PHP: Using functions/expressions in HEREDOC strings
29
Mar2011
If you have any experience with PHP at all, you’ve probably used HEREDOC strings.
The syntax is quite useful for long strings that span on multiple
lines, but I always disliked the fact that if you wanted to use the
result of a function, you need to store it in a variable as an
intermediate step:
Unfortunately, PHP doesn’t provide any direct means for calling
functions or outputting expression results in HEREDOC strings. The
problem here is that, unless the thing in the curly braces starts with a
dollar sign, it can’t be recognized by PHP as something to be replaced –
you can’t just put {date(‘r’)}. Functions doesn’t start with a dollar
sign, so you can’t use them. Object methods work fine though, because
the object variable does start with a “$”.
We can use this behavior in order to devise a very neat workaround to our problem: if PHP wants a $ in the beginning, why don’t we just store the function name in a variable? That’s one of the less popular features of PHP – and for good reasons – but in this particular case it could be very useful. So, we can change our example above to this, and it will work:
Now, let’s step this up a bit, shall we? Take a look at this example:
Told you it was neat, isn’t it?
The “heredoc” function is just a wrapper – it accepts a single argument
which is returned unmodified, and the name of this function is stored
in a global variable that can be used anywhere in your application. The
name of the function and the name of the global variable are completely
customizable, so the “heredoc” name is just a suggestion. $heredoc()
will be called as a function, and the expression in the parentheses will
be evaluated as any other PHP code. The result of that expression will
be given to the heredoc function which, in its turn, just returns it and
puts it in the HEREDOC string.
http://blog.nazdrave.net/?p=626
1 2 3 4 | $time = date('r'); // example value: Tue, 29 Mar 2011 17:04:28 +0300 $string = <<<HEREDOC Now is {$time} HEREDOC; |
We can use this behavior in order to devise a very neat workaround to our problem: if PHP wants a $ in the beginning, why don’t we just store the function name in a variable? That’s one of the less popular features of PHP – and for good reasons – but in this particular case it could be very useful. So, we can change our example above to this, and it will work:
1 2 3 4 | $date_func = 'date'; // the name of the function as a string $string = <<<HEREDOC Now is {$date_func('r')} HEREDOC; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function heredoc($param) { // just return whatever has been passed to us return $param; } $heredoc = 'heredoc'; $string = <<<HEREDOC \$heredoc is now a generic function that can be used in all sorts of ways: Output the result of a function: {$heredoc(date('r'))} Output the value of a constant: {$heredoc(__FILE__)} Static methods work just as well: {$heredoc(MyClass::getSomething())} 2 + 2 equals {$heredoc(2+2)} HEREDOC; // The same works not only with HEREDOC strings, // but with double-quoted strings as well: $string = "{$heredoc(2+2)}"; |
http://blog.nazdrave.net/?p=626
jueves, 2 de abril de 2015
PHP goto
<?phpgoto a;
echo 'Foo';
a:
echo 'Bar';?>
Suscribirse a:
Entradas (Atom)