Skip to content

Instantly share code, notes, and snippets.

@jijihohococo
jijihohococo / search_string_and_highlight.js
Last active March 21, 2025 22:48
String highlight function within text.
search_string_and_highlight(str,searchData){
if(str == null || /^\s*$/.test(str) === 0 ){
return string
}
let string = str.toString()
let checkString = string.toLowerCase()
let span = '<span class="text-primary">'
let endSpan = '</span>'
if(searchData !== null){
let search = searchData
<?php
if(!function_exists('getRequestDomain')){
function getRequestDomain(){
if(isset($_SERVER['HTTP_ORIGIN'])){
return $_SERVER['HTTP_ORIGIN'];
}elseif(isset($_SERVER['HTTP_REFERER'])){
return substr($_SERVER['HTTP_REFERER'], 0, -1);
}
}
@jijihohococo
jijihohococo / isset_func.js
Created October 21, 2022 03:00
checking element in array
isset = (arrayKey,array) => array.includes(arrayKey);
<?php
if(!function_exists('getDomainName')){
function getDomainName(){
$http = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://' ;
$pageLink = isset($_GET['page']) ? str_replace('&page=', NULL,str_replace('?page=', NULL, substr_replace($_SERVER['REQUEST_URI'],NULL,-strlen($_GET['page'])))) : $_SERVER["REQUEST_URI"];
return $http . $_SERVER['HTTP_HOST'] . $pageLink;
}
}
<?php
if(!function_exists('jsonResponse')){
function jsonResponse(array $data,int $code=200){
header('Content-type:application/json');
http_response_code($code);
echo json_encode($data);
return TRUE;
}
}
<?php
function showPromotionPricePercentage( $price , $promotionPrice ){
return round( ( $price - $promotionPrice )*100/$price );
}
@jijihohococo
jijihohococo / secure_cookie.php
Created October 21, 2022 02:48
Saving and Removing Server Side Secure Cookies
@jijihohococo
jijihohococo / regex_for_name_validation.php
Last active October 23, 2022 12:54
Regex For Name Validation
<?php
function regexForNameValidation(){
return '^[A-Za-z_ ]+$';
}
<?php
class UserDevice
{
public const AVAILABLE_DEVICES = [
'mobile' => ['iPhone','Android'],
'computer' => ['Windows','Linux x86_64','Macintosh']
];
public static function getUserAgent(){
Morty Proxy This is a proxified and sanitized view of the page, visit original site.