PHP Codes Do Not Working!

Yestday I uploaded a php page to my php VPS hosting from hostgator, i uploaded the file via ‘Secure File Transfer Client’, and I log in my hosting using the username of ‘root’, and its related passwords.

After I uploaded the file, and run the php page, I can not let it working. After about 30 minutes thinking, I found that the hosting directory is belong to a username called ‘eyeglasses’, not ‘root’.

I logged in the centos system via SecureCRT, and run:


ls -l phpinfo.php
-rw-r--r-- 1 root root 28 Feb 24 17:54 phpinfo.php

My god, this file is belong to user name called root, and user group called root too. So I changed the username, and user group:

chown eyeglasses phpinfo.php
chgrp eyeglasses phpinfo.php

I have a check again:

ls -l phpinfo.php
-rw-r--r-- 1 eyeglasses eyeglasses 28 Feb 24 17:54 phpinfo.php

Now, I run the php page sucessfully!

Posted in Php Code. Comments Off »

Get first letter of each word


//get first letter of each word
//method a
$words = explode(" ", "Cheap prescription eyeglasses");
$acronym = "";

foreach ($words as $w) {
$acronym .= $w[0];
}

echo $acronym;

//method b
$words = preg_split("/\s+/", "Cheap prescription eyeglasses");
$acronym = "";

foreach ($words as $w) {
$acronym .= $w[0];
}
echo $acronym;

//method c

$words = preg_split("/[\s,_-]+/", "Cheap prescription eyeglasses");
$acronym = "";

foreach ($words as $w) {
$acronym .= $w[0];
}
echo $acronym;

//method d

$language = 'Cheap prescription eyeglasses';

$language = explode(" ", $language);

foreach ($language as $value) {
echo $firstLetter = $value[0];
}

//method e

$string = "Cheap prescription eyeglasses";

function initials($str) {
$ret = '';
foreach (explode(' ', $str) as $word)
$ret .= strtoupper($word[0]);
return $ret;
}

echo initials($string);

//method f
function createAcronym($string) {
$output = null;
$token = strtok($string, ' ');
while ($token !== false) {
$output .= $token[0];
$token = strtok(' ');
}
return $output;
}
$string = 'Cheap prescription eyeglasses';
echo createAcronym($string, false);

//method g

function createAcronym($string, $onlyCapitals = false) {
$output = null;
$token = strtok($string, ' ');
while ($token !== false) {
$character = mb_substr($token, 0, 1);
if ($onlyCapitals and mb_strtoupper($character) !== $character) {
$token = strtok(' ');
continue;
}
$output .= $character;
$token = strtok(' ');
}
return $output;
}
$string = 'Cheap prescription eyeglasses';
echo createAcronym($string);

//method h

function acronym( $string = '' ) {
$words = explode(' ', $string);
if ( ! $words ) {
return false;
}
$result = '';
foreach ( $words as $word ) $result .= $word[0];
return strtoupper( $result );
}

echo acronym( $string = 'Cheap prescription eyeglasses' );

//method i
$string = "Cheap prescription eyeglasses";
$strs=explode(" ",$string);

foreach($strs as $str)
echo $str[0];

//method j

$string = 'Cheap prescription eyeglasses';
$words = explode(' ', $string); // array of word
foreach($words as $word){
echo $word[0]; // first letter
}

//method k

$str = 'Cheap prescription eyeglasses';
echo implode('', array_map(function($v) { return $v[0]; }, explode(' ', $str)));

//method l

// initialize variables
$string = 'Cheap prescription eyeglasses';
$myCapitalizedString = '';

// here's the code
$strs=explode(" ",$string);
foreach($strs as $str) {
$myCapitalizedString .= $str[0];
}

// output
echo $myCapitalizedString; // prints 'Cpe'

*/
//method m

$string = "Cheap prescription eyeglasses";
$arr = explode(" ",$string);

foreach($arr as $s)
{
echo substr($s,0,1);
}

?>

Posted in Php Code, Php Skills. Comments Off »

Static Pages Link Display

How to stop part of static pages showing at homepage, help section, or both?

1. Not show at homepage only
Open file bottom.tpl, which is under fold of skin/2-columns/customer/, and change the following code:

{foreach from=$pages_menu item=p}
{if $p.show_in_menu eq 'Y'}

  • {$p.title|amp}
  • {/if}
    {/foreach}

    to:

    {foreach from=$pages_menu item=p}
    {if $pages_menu[pg].orderby gt "900"}

  • {$p.title|amp}
  • {/if}
    {/foreach}

    Posted in Php Code, X-Cart. Comments Off »

    Duplicate content on categories pages with multiple pages of x-cart

    I am working on my x-cart 4.4.5 site aajj.net. One thing I am running into is that I get duplicate content warnings on my categiries pages. For example… I have 200 products in a category with 20 products per page. This breaks the category up into 10 pages. The descriptive paragraph I have for the category is repeated on all 10 pages making a big chunk of duplicate content.

    Is there a way to add some code that will only show the category description paragraph on the 1st page if multiple pages are present?

    The answer is yes. We can modify subcategories.tpl, which is under skin/common_files/customer/main/.
    Change the following code:
    {if $current_category.description ne ""}

    {$current_category.description|amp}

    {/if}

    to:

    {if $current_category.description ne "" and $navigation_page < "2"}

    {$current_category.description}

    {/if}

    Posted in X-Cart. Comments Off »

    Adding custom text to bottom of all posts in particular category

    If we want to add the same piece of custom text to the bottom of every post in a certain category of wordpress. How do then?
    For example, we want to add “Good idea if you buy eyeglasses online!” at each page of category which category id is 2.

    Try to add the following code in your theme’s functions.php: (more…)

    Posted in WordPress. Comments Off »

    Bulk Generate Different Dates for Vbulletin

    We sometimes use php or mysql to generate many different user names, we found all users’ joining dates are the same. How to deal this issue then?

    Let me share my skills with you.

    <? function rand_time($a,$b) { $a=strtotime($a); $b=strtotime($b); return date( “Y-m-d H:m:s”, mt_rand($a,$b)); } $date1=”2012-02-20 08:15:42″; $date2=”2013-05-7 08:15:42″; $num = 2000; $i=0; while ($i < $num){  $date = rand_time($date1,$date2);  $date=strtotime($date);  $datea[]= $date;  $i++; }

    foreach ($datea as $values) { echo $values; echo “,<br>”;

    } ?>

    Posted in Vbulletin. Comments Off »

    Let WordPress Different Category Shows Different Style

    For example, we are designing a company site using wordpress, 2 categoris: product category, and new category. How to let these 2 categories show different styles?

    Creat 2 php files: product.php, news.php, and copy all contents from wp-content/themes/zeecompany/archive.php;
    Edit wp-content/themes/zeecompany/archive.php, delete all contents in archive.php, and copy the following code in archive.php: (more…)

    Posted in WordPress. Comments Off »

    Useful Drupal Skills

    How to show a block only at front page or homepage?
    1. Go to Administration » Structure;
    2. Click ‘Add block’, and fill in “Add block”, and your code at “Add block”;
    3. Under “Show block on specific pages”, Click “Pages on which this PHP code returns TRUE (experts only)”, and copy the folling code in the blank box:

    if (drupal_is_front_page()) {
    return true;
    }
    ?>

    Posted in Drupal. Comments Off »

    Change mangeto domain name

    4 steps:
    first, upload all files to your new web hosting;
    second, restore your mysql database to your new one;
    third, edit /app/etc/local.xml, and update to your new mysql database information, take care the following code:
    (more…)

    Posted in Magento. Comments Off »

    How do I quickly delete all “Url Rewrite Management” urls in the magento database?

    If your store is not live yet. Follow this:
    1) Empty/Truncate core_url_rewrite table from Database.
    2) Disable Permanent Redirects from Magento Backend.
    3) Reindex Catalog URL Rewrites and all your URL’s will be corrected. (more…)

    Posted in Magento. Comments Off »
    King Php Science Designed by:KingPhp.com Welcome, you are from: 66.249.65.140