Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:52:36+00:00 2026-06-14T18:52:36+00:00

Possible Duplicate: regex help with getting tag content in PHP At first, please no

  • 0

Possible Duplicate:
regex help with getting tag content in PHP

At first, please no comment about parsing html with regex. I know that it is not possible but it should do its job in this case.

I try to get the content of <country lan="x">...</country> tags. There is no special case like <country /> and the PHP DOM Parser fails due to the content of the tags which contains many special chars (MediaWiki text).

So I have some text like

    <country lan="en">


    dsadasd


    {|,'''""" }}|]][][]//\\\\\2r2erfaf<>><<<#<div> --..,;;"!"§$%&/()=?`´´``***+~~~''

    0131ß

    ÄÜÖ#ax
    </country>

My solution at the moment is $pattern = <country lan=\"en\">(.|\t|\r|\n|\s)*<\/country> which seems to match using

preg_match_all($pattern, $content, $matches);
print_r($matches);

but the printed result is just an empty array. How can I extract only the string between the <country lan="x">...</country> tags?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:52:38+00:00Added an answer on June 14, 2026 at 6:52 pm

    Use this one

    preg_match_all('/<country.*?>(.*?)<\/country>/s', $contents,$hits);
    print_r($hits);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Regex Remove Images with style tag from Html PHP XML remove element
Possible Duplicates: How do I extract HTML content using Regex in PHP RegEx match
Possible Duplicate: php regex , extract phone number from text/html I have following requirement.
Possible Duplicate: php regex to get string inside href tag I have a text
Possible Duplicate: Regex for matching javadoc fragments I have files having content like /**
Possible Duplicate: PHP REGEX: Get domain from URL I am working on a project
Possible Duplicate: PHP remove special character from string I want to find a regex
Possible Duplicate: Regex exec only returning first match a1b2c3d.replace(/[0-9]/g,x) returns axbxdxd as expected. /[0-9]/g.exec(a1b2c3d)
Possible Duplicate: How to parse and process HTML with PHP? I am trying to
Possible Duplicate: RegEx match open tags except XHTML self-contained tags I have a HTML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.