PHP scripts and programs for Beginner to Master

php programs, php ready to use scripts & functions, css tutorials, html, javascripts, ajax examples for Beginner to Master

Have you ever came across a situation where you need to truncate the large text and show the "read more.." link to redirect user to read the full post ?
I know you might be searching for a function to show read more link in php.

Here is our simple function which can be used to show the "Read more.." links dynamically.



The above function can be used anywhere to show read more links with dynamic mysql queries.

How to use this function ???
Here is a simple example to do this
First you will need to create the connection with the database.
Connection settings are stored in "connect.php" file




This will output your article text with proper linking to original post with read more link.

Even you can customize the truncate function for more security check and customizing your display.

Share with friends if you liked it.

So you installed WampServer on Windows.

Now how to create and execute or run you php file on windows ???

First START WampServer by clicking your START MENU and then selecting WampServer and then click start WampServer.

Once Server is started then you will see a WampServer icon in the right corner of your taskbar where your clock is present.

Now open the drive where you installed your wampserver.(ex. C:/wamp/)
Then open the www folder. (ex. C:/wamp/www/)
This is your Base directory, your all projects will come here.

Now create a directory here named mytest.
Now open notepad or any other text editor you have. Type the following in it.





Save the file to the directory mytest as index.php


Now click on the icon present in the right hand side of your taskbar and then click on localhost
Now you will see the list of projects, then click on mytest, you can see that your program is executed.
It will show you all the details of the php version you have installed.

Many of us use windows operating system and want to know how to use php on Windows operating system ?

For this there is a very simple and useful solution. Even you don't have to setup & configure many things.

Following things are required for using php on windows


  • Apache Server
  • Mysql
  • PHP
WampServer is a Windows web development environment. With this we can create web applications with Apache, PHP and the MySQL database. Even PHPMyAdmin is provided to manage your databases.

Just Download WampServer and install it and you are done. WampServer is an open source project, free to use.

Hi Friends, programming-in-php.blogspot.com is a place to share experience and knowledge.

You can Help us to spread the word either by forwarding this URL or putting this on your blog or website.
Even I am thinking of putting a section which will list the useful resources for programming, so if you have a blog or website which is related to php, php codes, php scripts, ajax, css, html,open source or if its technical blog then please contact me by writing a comment here about your blog, i will definitely like to add your link here on my blog.
Because to share our knowledge it has to be accessible to other many people. So lets help each other to share knowledge.


We all can have a section on our blog or website to share some useful resources which also helps in link building & SEO(Search Engine Optimization) and promotion.

Your comments are always welcome about this idea, whether is good or bad.
I am waiting for your reply.

Thank you.

At many places we require the contact us or feedback form to get some input from the user or to get some feedback from the user.
Today i will be showing you how to create a very simple feedback form or contact us form in php with the mail function and without any database.

1) First we will be creating a simple form to accept the user input like name, email and their message or feedback or query.





















Name : "/>
Email : "/>
Message :
 





2) In the form tag we have not specified any action part and we kept action="" in the form tag, so when the form is submitted at that time it will call itself.
So on submit we will execute our code to send the mail.





3) some css for the form and good look.

.textbox,.textarea {
width:300px;
border:solid 2px #00CCFF;
padding:3px;
margin:10px;
}
.error {
background: #FBBFDC;
color:#EF013D;
border:solid 1px;
padding:5px;
margin:5px;
}


4) After the page is submitted we will process the form data.



5) When the form is filled then we will be calling a function sendmail.



Finally, merge all the code to create a simple contact us form or feedback form.
Full source code is here for your reference



.textbox,.textarea {
width:300px;
border:solid 2px #00CCFF;
padding:3px;
margin:10px;
}
.error {
background: #FBBFDC;
color:#EF013D;
border:solid 1px;
padding:5px;
margin:5px;
}




















Name : "/>
Email : "/>
Message :
 



if(isset($_POST["Submit"]))
{
$email = $_POST["email"];
$msg = $_POST["message"];
$username = $_POST["name"];
if($username!="" and $email!="" and $msg!="")
{
sendmail($username,$email,"",$msg,"");
}
else
{
echo "
Fill all the fields ! Thank you.
";
}
}
function sendmail($username,$email,$data,$msg,$footer)
{
$to="youremailidhere";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
//$headers .= "From: ".$from."\r\n";
$headers .= "From: $username <$email>\r\n";
$headers .= "Reply-To: youremailidhere\r\n";

$body="

Dear Admin,

";
$body.="

Message from : $username

";
$body.="

Email id : $email

";
$body.="

Message : $msg

";

$body.="Feedback end

";

if(@mail($to,'feedback from http://programming-in-php.blogspot.com',$body,$headers))
{
echo "Thank you for your valuable feedback !";
}
else
{
echo "
Can't send email ! ! !
";
}
}
?>

sometimes it is required to get the current working directory of the script.
so to get the current working directory in php this is a small function.