- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP preg_split with hyphen?
Use preg_split() in PHP and split with hyphen. Let’s say the following is our input value with numbers and string separated with hyphen
$values ="ABC-DEF IJKL-3553435-8990987876";
We want the output to be
Array ( [0] => ABC-DEF IJKL [1] => 3553435 [2] => 8990987876 )
Example
The PHP code is as follows
<!DOCTYPE html> <html> <body> <?php $values ="ABC-DEF IJKL-3553435-8990987876"; $exploded = preg_split('/-(?=[0-9])/', $values, 3); print_r($exploded); ?> </body> </html>
Output
This will produce the following output
Array ( [0] => ABC-DEF IJKL [1] => 3553435 [2] => 8990987876 )
- Related Articles
- PHP preg_split to split a string with specific values?
- Extract numbers after the last hyphen in PHP?
- Replacing space with a hyphen in C++
- MySQL left padding with zeros separated by hyphen?
- How to concatenate string vectors separated with hyphen in R?
- MySQL select for exact case sensitive match with hyphen in records
- How to set a string with hyphen and numbers in MySQL varchar?
- MySQL query to remove numbers after hyphen in a VARCHAR string with numbers
- Splitting a hyphen delimited string with negative numbers or range of numbers - JavaScript?
- Combine values of two columns separated with hyphen in an R data frame.
- Python Program to Take in a String and Replace Every Blank Space with Hyphen
- Hyphen string to camelCase string in JavaScript
- How to add hyphen between words in Excel?
- Finding the minimum and maximum value from a string with numbers separated by hyphen in MySQL?
- MySQL query to separate and select string values (with hyphen) from one column to different columns

Advertisements