Monday, May 18

Given string or char available in the word or not using PHP: strpos() method

Hi Guys,

The problem here is that strpos() returns the starting position index of $str2 in $str1 (if found), otherwise it returns false. So in this example, strpos() returns 0 (which is then obtain to false when referenced in the if statement). That’s why the code doesn’t work properly.

The correct solution would be to explicitly compare the value returned by strpos() to false as follows:

$str1 = 'gamechanger';
$str2 = 'change';
if(strpos($str1,$str2) !== false) {
    echo $str1 . " contains " . $str2 ;
} else {
    echo  $str1 . " does not contain " . $str2 ;
}


Without false condition it will execute the false statement ( else part).

Result

gamechanger contains changer

Tuesday, May 5

Course backup in Moodle

Hi Guys,


Course Backup.

1.    Go into the course.
2.    Click the Backup link either in the gear menu or the Administration block (Right corner).
3.    Initial settings - Select activities, blocks, filters and other items as required then click the Next button.
Uncheck the items for import and create new course. Else leave it as it is

Include enrolled users
Anonymize user information
Include user role assignments

Rest of things leave it as it is.
4.    Schema settings - Select/deselect specific items to include in backup, then click the Next button.
5.    If desired, select specific types of activity to be backed up by clicking the link 'Show type options'
6.    Confirmation and review - Check that everything is as required, using the Previous button if necessary, otherwise click the 'Perform backup' button.
7.    Complete - Click the Continue button.

Course Import in Moodle LMS

Hi Guys,


Course Import

   1.      Create new course.
  1. Inside the new course. click the Import link in the gear menu or the Administration block (Right corner).
  2. It will show the all the courses.
  3. Select the course you wish to import from and click Continue.
  4. You will be presented with the "backup settings" page. Use the check boxes for import activities, blocks and or filters as types of items which will show on the next screen.
  5. Select the elements you want to include in the import in the Schema settings step.
  6. Review and click Perform import or click the cancel or previous buttons. The confirmation page will place green check marks and red marks next to the backup settings and include item list for you to review.
8.      You should see the "Import complete. Click continue to return to the course." message, or an error message indicating that the import process did not take place.

Saturday, April 25

How to remove specific element from an array? Using PHP



$array = array('Apple', 'Orange', 'Strawberry', 'Blueberry', 'Kiwi', 'Mango');

echo "Initial array values </br>";
Print_r($array);

if (($key = array_search('strawberry', $array)) !== false) {
    unset($array[$key]);
}

echo "</br> Result </br>";
Print_r($array);


Initial array values
Array ( [0] => apple [1] => orange [2] => strawberry [3] => blueberry [4] => kiwi )
Result
Array ( [0] => apple [1] => orange [3] => blueberry [4] => kiwi )

 Note: Using unset in the array search option to resolve the problem

Second method to resolve the issue.


$myarray = array('Apple', 'Orange', 'Strawberry', 'Blueberry', 'Kiwi');
echo "Initial array values </br>";
Print_r($myarray);

foreach (array_keys($myarray, 'Strawberry') as $key) {
    unset($myarray[$key]);
}

echo "</br> Result </br>";
Print_r($myarray);

Initial array values
Array ( [0] => Apple [1] => Orange [2] => Strawberry [3] => Blueberry [4] => Kiwi )
Result
Array ( [0] => Apple [1] => Orange [3] => Blueberry [4] => Kiwi )



Note: Using unset option in Array key to resolve the issue

Remove single option from the selection list in PHP


// Array 

$myarray = $cars = array("Orange", "Apple", "Banana", "Cherry","Mango","Papaya");

echo "Initial array values </br>";
Print_r($myarray);

$value = "Papaya";  // remove value from the List

$options = array_diff($myarray, (is_array($value) ? $value : array($value)));

echo "</br> Result </br>";
Print_r($options);


Initial array values
Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry [4] => Mango [5] => Papaya )

Result
Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry [4] => Mango )


Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...