Remove last character from a string php
Use this code:
$string = ‘You rock’;
$string2 = substr_replace($string ,”",-1);
echo ”.$string2.”;
It will just remove the “k” letter from your string.
Use this code:
$string = ‘You rock’;
$string2 = substr_replace($string ,”",-1);
echo ”.$string2.”;
It will just remove the “k” letter from your string.
Categories: Beginner Tags:
Well this can become a storage of resources so here is how to deal with diacritics:
If you have a text with diacritics and want to do with str_replace on the text you can, but when getting the text from a sql db they will still be in diacritics even if you apply the same replace to them, so how to do it?
Add this code before your “select *
mysql_query(“SET NAMES utf8″);
That’s it, now the text will be with normal diacritics and can be replaced with str_replace.
Categories: Info Tags:
Let`s say you want to make a counting at your resulted sql entries like:
$SQL = mysql_query(“SELECT * FROM table”, $connection);
$i = 1;
while ($r = mysql_fetch_array))
{
echo”.$r['entry'].’, number ‘.$i.’
$i++;
}
If you have 2 entries in your db you will get in echo:
entry 1, number 1 and entry 2, number 2.
Meaning you don`t need while for $i++ and other while for the SQL SELECT * FROM
Categories: Beginner Tags:
Is very easy:
Use strlen,
example:
$s = ‘Monica has an apple’;
$count = strlen($s);
echo”.$count.”;
So it will result a number, meaning how many character has that string.
It can be useful if you want to create something like a [...] to an article making with an if:
if ($count > 130)
{
echo’[...]‘;
}
else
{
echo”;
}
so if the article has less than 130 characters you should not have a [...] at its end.
Categories: Beginner Tags:
So you are in phpmyadmin.
Just create a table with 4 rows.
id – stands for the number of the entry – set it to int
name – varchar – 255 max characters
text – text – about 5000 or more characters.
That is all, you got your sql database.
Categories: Beginner Tags:
To make the connection with the sql database you need a config.php
What should contain:
<?
$dbadress = “localhost”;
$dbname = “——–”;
$dbuser = “————–”;
$dbpass =”————–”;
$connection = mysql_connect($dbadress, $dbuser, $dbpass) or die (“Cannot connect to MySQL!”);
mysql_select_db($dbname, $connection) or die (“I cannot find the db!”);
?>
Make this
<? include (‘config.php’); ?>
every time you want to do something to the sql database, select, delete, update, etc.
Categories: Beginner Tags:
The best way to manage a website structure is to make it with php include.
So you can change a header and that change to take effect for all the webpages of the website.
Usually you need:
Header
Main content
Right side / left side (optional)
Footer.
Create these 5 / 3 pages and add in index.php
<?
include (‘header.php’);
include (‘maincontent.php’);
include (‘footer.php’);
?>
Also left and right side if you got those.
Categories: Tutorials Tags:
Or object oriented programing.
An easy way to make a webpage easy to manage either by the coder or the designer.
All the code will just stay in one php page, and those codes will be used by a line of code.
You can create functions in that page as many as you want.
Categories: Info Tags:
An ideea was to generate an image in php and add that image into a pdf using fpdf from fpdf.org.
Other way is to pass all the data and code into the pdf wich is the best way but the hardest way.
Visit fpdf.org and download their miniscript, also there are lots of tutorials there that will make you understand how to convert php to pdf.
With the image was only an ideea, after I would create that script expect that this post to contain it.
Categories: Info Tags:
Create a table in sql.
id – int
name = varchar
phone = varchar
email = varchar
city = varchar
So we can get the name, email, phone and city of the person who will send us a message.
<form name=”contact” action=”contactproc.php”>
<input name=”name” type=”text” value=”">
….
add for phone email and city the same line as above only changing the name of the input then
<input name=”submit” type=”submit” value=”Send message”>
</form>
Add a second php file called contactproc.
<?
$name = $_POST['name'];
….
same for city, phone, email.
$insert = “INSERT INTO contact (`name`, `phone`, `email`, `city`) VALUES (‘$name’, ‘$phone’, ‘$email’, ‘$city’);”;
mysq_query($insert);
?>
Categories: Tutorials Tags: