Code Snippets

Category

15 posts found

31 Mar 2019
1.37K
No Comments

I’ve wrote add_subdomain_in_url function and it will help you in easily add sub domain in url by passing in parameters and look output result. [php] function add_subdomain_in_url($url,$subdomain){ $www_pos = strpos($url,’www.’); $non_www_pos = strpos($url,’://’); if($www_pos!==false){ return substr($url,0, $www_pos+4).$subdomain.’.’.substr($url,$www_pos+4); } else if($non_www_pos!==false){ return substr($url,0, $non_www_pos+3).$subdomain.’.’.substr($url,$non_www_pos+3); } else { return $subdomain.’.’.$url; } }

Post in

17 Mar 2019
3.13K
No Comments

New version 7.2 of PHP is little bit restrict for calling functions and passing parameters, now count() function will only count variable and it will thrown an error when parameter is not array. Here is quick fix I have create my own function for counting array or object and it

Post in

10 Jul 2018
0.51K
No Comments

I need that function to delete 10 minutes old files from my project, remove_x_minutes_old_files function required two parameters $path for directory path and $in_minutes for minutes how much old file you want to delete. [php] function remove_x_minutes_old_files($path,$in_minutes=10){ $minutes_in_seconds = $in_minutes*60; $now_unix_time = strtotime(‘now’); $d2 = array(‘.’,’..’); $dirs = array_diff(scandir($path),$d2); foreach($dirs

Post in

29 Dec 2017
0.84K
No Comments

This function I was made specially for my theme which is running in this blog. I made function because Gravatar generate random images on each user’s avatar if user not uploaded real image, this function will not work no localhost so please use domain path eg: domain.com/wp-content/themes/mytheme/images/DefaultAvatar.jpg [php] function getavatar_src($author_idOrEMAIL=0,$size=50){

Post in

29 Nov 2017
0.61K
No Comments

In Current 4.9 or preview versions we cannot get the_excerpt or get_the_excerpt by post ID so here is a little bit hack code to get excerpt paragraph of post by postID with alternate code [php] $postID=1; $postDATA = get_post($postID); $wordLength = 15; echo wp_trim_words( strip_shortcodes($postDATA->post_content) ,$wordLength); [/php

Post in

23 Mar 2017
0.89K
No Comments

[php] use Auth; class SDTuts_LaravelController extends Controller{ } [/php

Post in

23 Mar 2017
0.56K
No Comments

[php] use Illuminate\Support\Facades\Input; class SDTuts_LaravelController extends Controller{ function SDTuts_LaravelMethod(){ Input::get(‘param’); Input::post(‘param’); } } [/php

Post in

23 Mar 2017
0.48K
No Comments

[php] <?php namespace App\Http\Controllers\theController; use Illuminate\Routing\Controller as BaseController; class theController extends BaseController{ [/php

Post in

23 Mar 2017
0.25K
No Comments

[php] wrong {!! Form::text(‘ctitle’, ”, array_merge([‘id’=>’ctitle’,’class’ => ‘form-control’,’value’=>$c_data[‘title’]])) !!} right wrong {!! Form::text(‘ctitle’, $c_data[‘title’], array_merge([‘id’=>’ctitle’,’class’ => ‘form-control’])) !!} [/php

Post in

23 Mar 2017
0.24K
No Comments

[php] {!! Form::password(‘password’, [‘class’ => ‘form-control’,’placeholder’=>’Enter password’,’required’=>”,’tabindex’=>’2′]) !!} [/php

Post in