23 February 2023

How to add color according to first letter of text in PHP?

Add color according to first letter of text in PHP

<?php

$name = "jaspreet";

$initial = strtoupper(substr($name, 0, 1)); // Get the first letter and convert it to uppercase

$color = '#' . substr(md5($initial), 0, 6); // Generate a 6-digit hexadecimal color code from the MD5 hash of the initial

echo "<div style='background-color: $color;'>$initial</div>"; // Display the initial inside a div element with the generated color as the background color

?> 

How to use "FIND_IN_SET" in mysql query?

Use "FIND_IN_SET" in mysql query? 

Column = chat_group with value (k,h,p)

SELECT * FROM `tester` WHERE FIND_IN_SET('k', chat_group);

Opposite Result

SELECT * FROM `tester` WHERE NOT FIND_IN_SET('w', chat_group);

How to add "Not Found" text into empty div or by specific class in jquery?

Add Not Found text into empty div or by specific class in jquery


<!DOCTYPE html>

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

var not_found_dt = "<div class='not_found_dt'>Not Found</div>";

var demo_str = $('#demo').text();

demo_str = demo_str.replace(/\s/g, '');

if(demo_str.length == 0){

$('#demo').html(not_found_dt);

}

});

</script>

</script>

</head>

<body>


<div id="demo"></div>


</body>

</html>

13 February 2023

How to get data from XML file in PHP?

Get data from XML file in PHP



$rss_link = "http://xyogasangeetax.api.channel.livestream.com/2.0/latestclips.xml"; //xml_file_link   

// Load xml data.
$xml = file_get_contents($rss_link);
// Strip whitespace between xml tags
$xml = preg_replace('~\s*(<([^>]*)>[^<]*</\2>|<[^>]*>)\s*~','$1',$xml);
// Convert CDATA into xml nodes.
$rss_feed = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA

$rss_feed_channel = $rss_feed->channel;

$rss_feed_channel_item = $rss_feed->channel->item 

                                                         or

$rss_link = "http://xyogasangeetax.api.channel.livestream.com/2.0/latestclips.xml"; //xml_file_link   

//$rss_feed = simplexml_load_file($rss_link, 'SimpleXMLElement', LIBXML_NOCDATA);

   $rss_feed = file_get_contents($rss_link);

   //mb_convert_encoding($rss_feed, 'UTF-16LE', 'UTF-8');

   $rss_feed = new SimpleXmlElement($rss_feed); 

$rss_feed_channel = $rss_feed->channel;

$rss_feed_channel_item = $rss_feed->channel->item 


or

$context = stream_context_create( array( 'http' => array( 'follow_location' => false ) ) ); 

$content = file_get_contents("http://xyogasangeetax.api.channel.livestream.com/2.0/latestclips.xml", false, $context); 

$data = new SimpleXmlElement($content); 

foreach($data->channel->item as $entry) 

    { if ($media = $entry->children('media', TRUE)) 

        { echo "<div style=\"width:160px;display:block;float:left;padding:15px;\">"; 

        $attributes = $media->content->attributes(); 

        $src = $play_attributes['url']; 

            if ($media->thumbnail) 

                    { $attributes = $media->thumbnail->attributes(); 

                    $imgsrc = (string)$attributes['url']; 

                    echo "<img src=\"$imgsrc\" alt=\"\" \/>"; 

                    } 

        } 

$pub_date= explode("-",$entry->pubDate); 

echo date('F d,Y',strtotime(trim($pub_date[0]))); 

echo "</div>"; }

08 February 2023

How to insert form in url and read data from url without refresh page?

Insert form in  url and read data from url without refresh page


<html>
    <head>
    <script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
    </head>
    <body>
        <Form action="" method="get" id="search_form">
            <input type="text" name="first_name" value="demo">
            <input type="text" name="last_name" value="tester">
            <input type="text" name="city" value="sangrur">
            <input type="submit" name="submit" value="Submit">
        </Form>
    </body>
    <Script>
        jQuery("document").ready(function($){
            $('#search_form').submit(function(e){
                e.preventDefault();
                var search_form = $(this).serialize();
                var refresh = window.location.protocol + "//" + window.location.host + window.location.pathname + '?arg=1&' + search_form;    
                window.history.pushState({ path: refresh }, '', refresh);

                var current_url = window.location.href;
                var url_data = parseURLParams(current_url);
                console.log(url_data);
                console.log(url_data['first_name']);
                
            })


            function parseURLParams(url) {
                var queryStart = url.indexOf("?") + 1,
                    queryEnd   = url.indexOf("#") + 1 || url.length + 1,
                    query = url.slice(queryStart, queryEnd - 1),
                    pairs = query.replace(/\+/g, " ").split("&"),
                    parms = {}, i, n, v, nv;

                if (query === url || query === "") return;

                for (i = 0; i < pairs.length; i++) {
                    nv = pairs[i].split("=", 2);
                    n = decodeURIComponent(nv[0]);
                    v = decodeURIComponent(nv[1]);

                    if (!parms.hasOwnProperty(n)) parms[n] = [];
                    parms[n].push(nv.length === 2 ? v : null);
                }
                return parms;
            }
        });
    </Script>
</html>

16 January 2023

How to get YouTube Video id from YouTube url?

 Get YouTube Video id from YouTube url?



<?php


$url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);
$youtube_id = $match[1];
echo $youtube_id ;

?>

How to embed(Link) youtube video by jquery?

Embed(Link) youtube video by jquery

 
<html>

<head>

<style>


.cus-embed-youtube {

  background-color: #000;

  margin-bottom: 30px;

  position: relative;

  padding-top: 56.25%;

  overflow: hidden;

  cursor: pointer;

}


.cus-embed-youtube img {

  width: 100%;

  top: -16.84%;

  left: 0;

  opacity: 0.7;

}


.cus-embed-youtube .cus-embed-youtube-play {

  width: 68px;

  height: 48px;

  background-color: #333;

  box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);

  z-index: 1;

  opacity: 0.8;

  border-radius: 6px;

}


.cus-embed-youtube .cus-embed-youtube-play:before {

  content: "";

  border-style: solid;

  border-width: 15px 0 15px 26.0px;

  border-color: transparent transparent transparent #fff;

}


.cus-embed-youtube img,

.cus-embed-youtube .cus-embed-youtube-play {

  cursor: pointer;

}


.cus-embed-youtube img,

.cus-embed-youtube iframe,

.cus-embed-youtube .cus-embed-youtube-play,

.cus-embed-youtube .cus-embed-youtube-play:before {

  position: absolute;

}


.cus-embed-youtube .cus-embed-youtube-play,

.cus-embed-youtube .cus-embed-youtube-play:before {

  top: 50%;

  left: 50%;

  transform: translate3d(-50%, -50%, 0);

}


.cus-embed-youtube iframe {

  height: 100%;

  width: 100%;

  top: 0;

  left: 0;

}


.cus-embed-youtube .cus-embed-youtube-play:hover {

  background-color: #f00;

}



</style>

</head>

<body>



<?php



$url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";

preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);

$youtube_id = $match[1];



if(!empty($youtube_id)){

?>

<!-- 1. Video Wrapper Container -->

<div class="cus-embed-youtube" data-video-id="<?php echo $youtube_id; ?>">

  <!-- 2. The preview button that will contain the Play icon -->

  <div class="cus-embed-youtube-play"></div>

</div>

<?php

}

?>


<!-- 1. Video Wrapper Container -->

<div class="cus-embed-youtube" data-video-id="dQw4w9WgXcQ">

  <!-- 2. The preview button that will contain the Play icon -->

  <div class="cus-embed-youtube-play"></div>

</div>

</body>

<script>

(function(){

  let YouTubeContainers = document.querySelectorAll(".cus-embed-youtube");


  // Iterate over every YouTube container you may have

  for (let i = 0; i < YouTubeContainers.length; i++) {

    let container = YouTubeContainers[i];

    let imageSource = "https://img.youtube.com/vi/"+ container.dataset.videoId +"/sddefault.jpg"; 


    // Load the Thumbnail Image asynchronously

    let image = new Image();

    image.src = imageSource;

    image.addEventListener("load", function() {

      container.appendChild(image);

    });


    // When the user clicks on the container, load the embedded YouTube video

    container.addEventListener("click", function() {

      let iframe = document.createElement( "iframe" );


      iframe.setAttribute("frameborder", "0");

      iframe.setAttribute("allowfullscreen", "");

      iframe.setAttribute("allow", "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture");

      // Important: add the autoplay GET parameter, otherwise the user would need to click over the YouTube video again to play it 

      iframe.setAttribute("src", "https://www.youtube.com/embed/"+ this.dataset.videoId +"?rel=0&showinfo=0&autoplay=1");


      // Clear Thumbnail and load the YouTube iframe

      this.innerHTML = "";

      this.appendChild( iframe );

    });

  }

})();

</script>

</html>

How to create video slider with cuncks of videos without download all videos?

 Create video slider with cuncks of videos without download all videos function custom_video_slider_shortcode() { $slider_id = 'vide...