Posts Tagged with php

Displaying 21-30 of 59 results.
Resolved: How to clear browser cache when re-uploading image with same filename, in php?
posted by admin on June 18, 2016
I have a listing of items, that also contains an image thumbnail. Sometimes I need to change the thumbnail image, but keep the filename the same. Is there a way to force the browser to download the newly uploaded image, instead of grabbing one from the browser cache?

This is very pertinent when people update their avatars, which causes confusion for some users, who keep seeing their old avatar, until they clear the browser cache, or restart the browser.Read more
Resolved: PHP filesize MB/KB conversion
posted by admin on June 18, 2016
How can I convert the output of PHP's filesize() function to a nice format with MegaBytes, KiloBytes etc?

like:
  • if the size is less than 1 MB, show the size in KB
  • if it's between 1 MB - 1 GB show it in MB
  • [*] if it's larger - in GBRead more
    Resolved: Parse error: syntax error, unexpected '[', expecting ')'
    posted by admin on June 3, 2016
    I have error in oscarotero Embed APP.Read more
    Resolved: error :should not be called statically, assuming $this from incompatible context. only on my machine
    posted by admin on June 3, 2016
    My team members wrote the model function calls in the controller statically such as:

    $data = ModelName::functionName($param);

    while it should be called dynamically such as:

    $model = new Model();
    $data = $model->functionName($param);

    mostly all the calls are made statically. the code is working on the server and on their local machines except for mine. And the static calls are too many to fix without rewriting huge code base.

    I always update my project via composer. My php version is 5.4.

    anyone might know what this is about?Read more
    Resolved: PHP get the first word of a sentence string
    posted by admin on May 22, 2016
    I want to extract the first word of a variable from a string. For example, take this input:

    <?php $myvalue = 'Test me more'; ?>

    The resultant output should be Test, which is the first word of the input. How can I do this?Read more
    Wiki: PHP strtotime() Functionwiki
    posted by admin on May 22, 2016
    Example
    Parse English textual datetimes into Unix timestamps:

    <?php
    echo(strtotime("now") . "
    ");
    echo(strtotime("3 October 2005") . "
    ");
    echo(strtotime("+5 hours") . "
    ");
    echo(strtotime("+1 week") . "
    ");
    echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "
    ");
    echo(strtotime("next Monday") . "
    ");
    echo(strtotime("last Sunday"));
    ?>

    Definition and Usage
    The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).

    Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

    Note: Be aware of dates in the m/d/y or d-m-y formats; if the separator is a slash (/), then the American m/d/y is assumed. If the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. To avoid potential errors, you should YYYY-MM-DD dates or date_create_from_format() when possible.

    Syntax

    strtotime(time,now);


    Parameter Description
    time Required. Specifies a date/time string
    now Optional. Specifies the timestamp used as a base for the calculation of relative dates

    Technical Details
    Return Value: Returns a timestamp on success. FALSE on failure
    PHP Version: 4+
    Changelog: PHP 5.3.0: Now relative time formats such as this week, previous week, last week, and next week interprets a week period of Monday through Sunday, rather then a 7-day period relative to the current date/time
    PHP 5.3.0: Now 24:00 is a valid format
    PHP 5.2.7: In earlier versions, if requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month it would incorrectly add one week to the returned timestamp. This has been corrected now
    PHP 5.1.0: Returns FALSE on failure (earlier versions returns -1), and issues E_STRICT and E_NOTICE time zone errors
    PHP 5.0.2: Now correctly computes "now" and other relative times from current time, not from today's midnight
    PHP 5.0.0: Allows microseconds (but they are ignored)Read more
    Resolved: PHP compose class property by string and value
    posted by admin on May 22, 2016
    I have object or class.

    class Class1{
    public $language = "English";
    public $languageru = "Russian";

    public function composeValue(){
    //return my value, or empty or "ru"
    }
    }

    $class = new Class1();
    $value = $class->composeValue();
    // I want something like this
    echo $class->language.$value
    //But it is not working
    Read more
    Resolved: Remove the last character(comma) from string
    posted by admin on May 6, 2016
    I have a string like

    a,b,c,d,e,


    I would like to remove last ',' and get the remaining string back

    OUTPUT: a,b,c,d,e
    Read more
    Resolved: PHP display an Array under alphabetical letters without key sensitive
    posted by admin on April 27, 2016
    I have an associative array of tags like

    array(11) {
    [0]=>
    array(4) {
    ["tag_id"]=>
    string(2) "81"
    ["slug"]=>
    string(4) "mag1"
    ["name"]=>
    string(4) "mag1"
    ["TagsCount"]=>
    string(1) "2"
    }
    [1]=>
    array(4) {
    ["tag_id"]=>
    string(2) "85"
    ["slug"]=>
    string(4) "mag2"
    ["name"]=>
    string(4) "mag2"
    ["TagsCount"]=>
    string(1) "1"
    }
    [2]=>
    array(4) {
    ["tag_id"]=>
    string(2) "83"
    ["slug"]=>
    string(4) "mag3"
    ["name"]=>
    string(4) "mag3"
    ["TagsCount"]=>
    string(1) "2"
    }
    [3]=>
    array(4) {
    ["tag_id"]=>
    string(2) "84"
    ["slug"]=>
    string(4) "mag4"
    ["name"]=>
    string(4) "mag4"
    ["TagsCount"]=>
    string(1) "2"
    }
    . . .
    [9]=>
    array(4) {
    ["tag_id"]=>
    string(2) "79"
    ["slug"]=>
    string(4) "tag5"
    ["name"]=>
    string(4) "tag5"
    ["TagsCount"]=>
    string(1) "1"
    }
    [10]=>
    array(4) {
    ["tag_id"]=>
    string(2) "80"
    ["slug"]=>
    string(4) "tag6"
    ["name"]=>
    string(4) "tag6"
    ["TagsCount"]=>
    string(1) "1"
    }
    }

    In output I want to see result like

    <h3>A</h3>
    <ol>
    <li>
    <em>tag count</em>
    <a href="link to tag">Animal</a>
    </li>
    <li>
    <em>tag count</em>
    <a href="link to tag">Aqua</a>
    </li>
    <li>
    <em>tag count</em>
    <a href="link to tag">Arthur</a>
    </li>
    </ol>
    <!-- if B not EXIST not show B -->
    <h3>C</h3>
    <ol>
    <li>
    <em>tag count</em>
    <a href="link to tag">Camel</a>
    </li>
    <li>
    <em>tag count</em>
    <a href="link to tag">Crazy</a>
    </li>
    </ol>
    <!-- etc -->
    Read more
    Wiki: PHP 5 Sorting Arrayswiki
    posted by admin on April 16, 2016
    The elements in an array can be sorted in alphabetical or numerical order, descending or ascending.

    PHP - Sort Functions For Arrays

    In this chapter, we will go through the following PHP array sort functions:
    • sort() - sort arrays in ascending order
    • rsort() - sort arrays in descending order
    • asort() - sort associative arrays in ascending order, according to the value
    • ksort() - sort associative arrays in ascending order, according to the key
    • arsort() - sort associative arrays in descending order, according to the value
    • krsort() - sort associative arrays in descending order, according to the key


    Sort Array in Ascending Order - sort()
    The following example sorts the elements of the $cars array in ascending alphabetical order:

    <?php
    $cars = array("Volvo", "BMW", "Toyota");
    sort($cars);
    ?>


    The following example sorts the elements of the $numbers array in ascending numerical order:

    <?php
    $numbers = array(4, 6, 2, 22, 11);
    sort($numbers);
    ?>


    Sort Array in Descending Order - rsort()
    The following example sorts the elements of the $cars array in descending alphabetical order:

    <?php
    $cars = array("Volvo", "BMW", "Toyota");
    rsort($cars);
    ?>


    The following example sorts the elements of the $numbers array in descending numerical order:

    <?php
    $numbers = array(4, 6, 2, 22, 11);
    rsort($numbers);
    ?>


    Sort Array (Ascending Order), According to Value - asort()
    The following example sorts an associative array in ascending order, according to the value:

    <?php
    $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
    asort($age);
    ?>


    Sort Array (Ascending Order), According to Key - ksort()
    The following example sorts an associative array in ascending order, according to the key:

    <?php
    $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
    ksort($age);
    ?>


    Sort Array (Descending Order), According to Value - arsort()
    The following example sorts an associative array in descending order, according to
    arsort($age);
    ?>
    [/php]

    Sort Array (Descending Order), According to Key - krsort()
    The following example sorts an associative array in descending order, according to the key:

    <?php
    $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
    krsort($age);
    ?>
    Read more