Cara menggunakan mysql regexp space

❮ PHP String Reference

Example

Wrap a string into new lines when it reaches a specific length:

$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"
\n");
?>

Try it Yourself »


Definition and Usage

The wordwrap() function wraps a string into new lines when it reaches a specific length.

Note: This function may leave white spaces at the beginning of a line.


Syntax

wordwrap(string,width,break,cut)

Parameter Values

ParameterDescriptionstringRequired. Specifies the string to break up into lineswidthOptional. Specifies the maximum line width. Default is 75breakOptional. Specifies the characters to use as break. Default is "\n"cutOptional. Specifies whether words longer than the specified width should be wrapped:
  • FALSE - Default. No-wrap
  • TRUE - Wrap


Technical Details

Return Value:Returns the string broken into lines on success, or FALSE on failure.PHP Version:4.0.2+Changelog:The cut parameter was added in PHP 4.0.3

More Examples

Example

Using all parameters:

$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"
\n",TRUE);
?>

Try it Yourself »

Example

Wrap a string into new lines:

$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>

The HTML output of the code above will be (View Source):




An example of a
long word is:
Supercalifragulistic

The browser output of the code above will be:

An example of a long word is: Supercalifragulistic

Try it Yourself »


❮ PHP String Reference

MySQL REGEXP performs a pattern match of a string expression against a pattern. The pattern is supplied as an argument.

If the pattern finds a match in the expression, the function returns 1, else it returns 0.

If either expression or pattern is NULL, the function returns NULL.

Syntax:

expr REGEXP pat

Argument

NameDescriptionexprA string expression.patA pattern whose match is to be found in the expression.

Note: As MySQL uses the C escape syntax in strings (for example, “\n” to represent the newline character), you must double any “\” that you use in your REGEXP strings. REGEXP is not case sensitive, except when used with binary strings.

MySQL Version: 5.6

Video Presentation

Your browser does not support HTML5 video.

Example of MySQL REGEXP operator using(^) find from beginning

The following MySQL statement will find the author’s name beginning with ‘w’. The ‘^’ is used to match the beginning of the name.

Code:

SELECT * FROM author 
WHERE aut_name REGEXP '^w';

Sample table: author


Sample Output:

mysql> SELECT * FROM author 
    -> WHERE aut_name REGEXP '^w'; 
+--------+-----------------+---------+-----------+
| aut_id | aut_name        | country | home_city |
+--------+-----------------+---------+-----------+
| AUT001 | William Norton  | UK      | Cambridge | 
| AUT002 | William Maugham | Canada  | Toronto   | 
| AUT003 | William Anthony | UK      | Leeds     | 
+--------+-----------------+---------+-----------+
3 rows in set (0.13 sec)

PHP script






example-regexp-function - php mysql examples | w3resource




List of authors with all their detail available, where name of the author must begin with 'w':

query('SELECT * FROM author WHERE aut_name REGEXP "^w"') as $row) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } ?>
Author's IDAuthor's nameCountryHome City
" . $row['aut_id'] . "" . $row['aut_name'] . "" . $row['country'] . "" . $row['home_city'] . "

View the example of REGEXP operator using(^) find from beginning in browser

JSP script

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>




example-regexp-function


<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String Host = "jdbc:mysql://localhost:3306/w3resour_bookinfo";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
connection = DriverManager.getConnection(Host, "root", "datasoft123");
statement = connection.createStatement();
String Data ="SELECT * FROM author WHERE aut_name REGEXP '^w'";
rs = statement.executeQuery(Data);
%>

<%
while (rs.next()) {
%>

<%   }    %>
Author's ID Author's name Country Home City
<%=rs.getString("aut_id")%> <%=rs.getString("aut_name")%> <%=rs.getString("country")%> <%=rs.getString("home_city")%>
<% rs.close(); statement.close(); connection.close(); } catch (Exception ex) { out.println("Cant connect to database."); } %>

Example of MySQL REGEXP operator using (^) with binary operator

The following statement will find the author’s name containing exactly 12 characters. Use ‘^’ and ‘$’ match the beginning and ending of the name and ‘{12}’ have been after ‘.’ for repeating ‘.’ twelve times.