Link to home
Create AccountLog in
Avatar of sukhoi35
sukhoi35

asked on

Trying to find patterns of substring in a larger string in PHP

I am trying to find all sub-strings in a webpage having the following format "<span>*******</span>". Here, **** can be any text;. So the output array should contain something like:

<span>New York</span>
<span>Paris</span>
<span>Sydney</span>
and so on.

I saw that there is a call 'preg_match_all'. Somehow, I couldn't come up with a proper regular expression for the same. Request experts to help me solve this problem.
SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of sukhoi35
sukhoi35

ASKER

Thanks for your response. One other pattern I am looking for is:

all text between the patterns:

</span>\n,(space)*******,  or    </span>\n,(space)*******\n

i.e. all text starting with</span> followed by a \n, comma, a single space and ending with a comma or \n. This is the expression i have come up with and it does not seem to work. Can you pls help?

"/\<\/span\>\\n,\" \",(.*)(,|\\n)/"
Any ideas?  :)
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thakns