Categories: PHP

quotemeta – PHP String Functions

Syntax :

quotemeta ( string );

Description :

The quotemeta() function adds backslashes in front of below characters.

The predefined characters are:

period (.)
backslash (\)
plus sign (+)
asterisk (*)
question mark (?)
brackets ([])
caret (^)
dollar sign ($)
parenthesis (())

Note : The function is binary-safe.
Tip: This function can be used to escape characters with special meanings, such as ( ), [ ], and * in SQL..

Parameter :

[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|lef|lef|left”]
Name, Required /Optional, Value Type, Description
string , Required, String , It is the input string.
[/table]


Output :

Returns the string with meta characters quoted, or FALSE if an empty string is given as string.


Related articles : htmlspecialchars_decode() ,nl2br() , stripslashes() , stripcslashes() , quoted_printable_encode() , addslashes() , addcslashes() , htmlentities() , htmlspecialchars().


quotemeta() – PHP Functions Example 1 :
<?php
$str = "Hi All. Thanks for reading my tutorials+!.";
echo quotemeta($str); 
?>

Output of above code in the browser is as below:

Hi All\. Thanks for reading my tutorials\+!\.

quotemeta() – PHP Functions Example 2 :
<?php
$strEg1 = "2 + 2 = 4";
$strEg2 = "3 * 2 = 6";
$strEg3 = "How are you?";
$strEg4 = "Are you Fine? (Yes, I am..)";
$strEg5 = "The caret [ ^ ] Looks like a hat!";
echo quotemeta($strEg1)."\n";
echo quotemeta($strEg2)."\n";
echo quotemeta($strEg3)."\n";
echo quotemeta($strEg4)."\n";
echo quotemeta($strEg5)."\n";
?>

Output of above code in the browser is as below:

2 \+ 2 = 4
3 \* 2 = 6
How are you\?
Are you Fine\? \(Yes, I am\.\.\)
The caret \[ \^ \] Looks like a hat!

jyoti rani

Recent Posts

What Is a Progressive Web App? Why Would You Need One?

App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…

11 months ago

7 Most Popular Paid Online Advertising Strategy

As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…

1 year ago

The Importance of User-Centered Design in Mobile App Development

Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…

1 year ago

Healthcare Mobile App Development: A Complete Guide for Founders

COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…

1 year ago

Exploring Diverse WordPress Theme Niches: A Comprehensive Guide

Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…

1 year ago

8 Awesome Blog Content Ideas for Movers to Skyrocket the SEO

For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…

1 year ago