Posts marked with "String" in tags

Replace Strings in Files With PHP & Python

There are softwares already that helps to replace a string in a file. Suppose, if you’re making a program that requires saving some data in to a file. By “adding”, the program is actually replacing a word. Let’s see how it’s done in PHPPython.

This is the file where we are going to replace the word :

thisWord
I got thisWord for making it thatWord
replace thisWord already my friend.

We replace the word “thisWord” to “thatWord” containing in this file.

... [READ MORE]

Word Palindrome Check in PHP & Python

Palindromes are unique words that are read the same forward and backward. We can identify them using out eyes and brain. How about we identify using a simple program in PHPPython ?

PHP

<?php
$word = strtolower("Malayalam");
$splitted = str_split($word);
$reversedWord = "";
$length = strlen($word);
for($i = 0; $i < $length; $i++)
	$reversedWord .= $splitted[$length - $i - 1];
echo $word == $reversedWord ? "It's a palindrome !n" : "It's not a palindromen";
?>

Instead of the loop to reverse the word, you can also use :

... [READ MORE]

Create Your Own URL Shortening Service Using PHP & jQuery

I made a URL shortening service a year back using PHP & jQuery. It was pretty simple. You should know the concept of URL Shortening. The concept is simple. When a user sends a request to short a URL, PHP will check if the URL is valid. If it’s valid then PHP will make a string of 5 or 6 characters. A folder is created with the name of this string and an index.php file with header function code is created in this folder. This will make the folder redirect to the URL the user requested. Since it’s a folder no extensions will be seen ! So You can make up some pretty good URL‘s.

... [READ MORE]

Generating Random String in PHP

In PHP you can generate random number by using rand function, but there is no specific function to generate a random text or string. In this post I’m going to show the function that will generate a random string of length mentioned.

Here is the function:

function rand_string($length) {
 $str="";
 $chars = "subinsblogabcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 $size = strlen($chars);
 for($i = 0;$i < $length;$i++) {
  $str .= $chars[rand(0,$size-1)];
 }
 return $str;
}

Usage

To generate a random string use rand_string() function with the parameter of length of the to be generated string. Here’s an example:

... [READ MORE]

Follow/Subscribe

Telegram 

Mastodon  Twitter

GitHub GitLab

Subdomains

Demos  Lab

Past

This blog was once on WordPress. Now a static site. See source code on

GitLab