473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I need help in Regular Expression in PHP

Hi Everyone,

How can I get all the values which are between Name tags as follows:

<emp>
<name>N1</name>
<age>1</age>

<name>N2</name>
<age>2</age>

<name>N3</name>
<age>3</age>

<name>N4</name>
<age>4</age>
</emp>


Regards
Zeeshan

Jul 17 '05 #1
6 2190
> Hi Everyone,

How can I get all the values which are between Name tags as follows:

<emp>
<name>N1</name>
<age>1</age>

<name>N2</name>
<age>2</age>

<name>N3</name>
<age>3</age>

<name>N4</name>
<age>4</age>
</emp>


Regards
Zeeshan

preg_match("/<name>.+?<\/name>/sim", $HTML, $matches);
Jul 17 '05 #2
Ivan Omelchenko 608308824 пишет:
Hi Everyone,

How can I get all the values which are between Name tags as follows:

<emp>
<name>N1</name>
<age>1</age>

<name>N2</name>
<age>2</age>

<name>N3</name>
<age>3</age>

<name>N4</name>
<age>4</age>
</emp>


Regards
Zeeshan

preg_match("/<name>.+?<\/name>/sim", $HTML, $matches);

sorry:
preg_match("/<name>(.+?)<\/name>/sim", $HTML, $matches);
^^^^^^
that's correctly
Jul 17 '05 #3
Thanks for reply good reg exp
But i am getting only one match for the string, i need all the matched
words

See code:
<?php
$HTML = "
<html>
<name>Shiva</name>
<form>
<name>Zeeshan</name>
<age>26</age>
<age>23</age>
</form>
</html>";
preg_match("/<name>.+?<\/name>/sim", $HTML, $matches);
print_r( $matches);
?>
Thanks again !

Regards
Zeeshan

Jul 17 '05 #4
Hello!
Thanks for reply good reg exp
But i am getting only one match for the string, i need all the matched
words


Use preg_match_all()

HTH
Hero Wanders
Jul 17 '05 #5
Can you please provide examples

Jul 17 '05 #6
Zeeshan said the following on 27/06/2005 11:02:
Can you please provide examples


http://www.php.net/preg_match_all

Same syntax as preg_match(), except with an extra argument which is an
array that the results of all the matches get put in.

(And a couple of extra flag options.)

If you have a regex working OK with preg_match(), then it should work
fine with preg_match_all().

--
Oli
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: Lucky | last post by:
hi guys, i'm practising regular expression. i've got one string and i want it to split in groups. i was trying to make one regular expression but i didn't successed. please help me guys. i'm...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
14
by: Chris | last post by:
I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = Can anybody help me out? Thanks for any help!
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.