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

  • SEARCH
  • Home
  • 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 8307605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:33:38+00:00 2026-06-08T18:33:38+00:00

Using regex and PHP I am trying to get the content of the title

  • 0

Using regex and PHP I am trying to get the content of the title attribute as below.

preg_match('/<abbr class="dtstart" title="([^"]*)"/i', $file_string, $starts);
$starts_out = $starts[1];

preg_match('/<abbr class="dtend" title="([^"]*)"/i', $file_string, $ends);
$ends_out = $ends[1];

Here is the exact part of the code that I want to get, and I get the data correctly.

<div id="eventDetailInfo">
    <h2>When</h2>
    <div class="p">
        <div>From:
            <abbr class="dtstart" title="2012-08-24T17:00:00">Friday, August 24th, 2012</abbr></div>
        <div>Until:
            <abbr class="dtend" title="2012-08-26">Saturday, August 25th, 2012</abbr></div>
    </div>
</div>

However, because sometimes there is no Until in some articles, the regex matches the first of the remaining code ( this is related articles).

My question is how do I restrict the regex to match only the above, and if no

<div>Until:
                <abbr class="dtend" title="2012-08-26">Saturday, August 25th, 2012</abbr></div>

is found, to remain blank?

This is the rest code of the page, unfortunately the regex matches it.

<div class="evdate">
    <em>When:</em>
    <abbr class="dtstart" title="2012-07-03T21:00:00">July 3rd</abbr>
    to
    <abbr class="dtend" title="2012-07-13">July 12th</abbr>*
</div>
<div class="evtime"><em>Time:
    </em>
    21:00
</div>
</div>
  • 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-08T18:33:39+00:00Added an answer on June 8, 2026 at 6:33 pm

    While I’ve shown you how to do this with a quick regex, I clearly advised you against using a regex for this sort of thing. As you can see for yourself, it can get out of hand rather quickly.

    As pointed out by others (here and there), you should be using an HTML parser for this.


    I’d advise you to use Simple HTML DOM, since it’s very easy to work with, and their documentation is pretty good too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PHP. I'm trying to get a Regex pattern to match everything between
I'm trying to parse a php code using some regex and I'm stuck at
Im parsing the source of a website and Im using this regex: /page\.php\?id\=([0-9]*)\\>(.*)\<\/a\>\<\/span\>/.match(self.agent.page.content) self.agent.page.content
I'm new to php and am trying to write a regular expression using preg_match
I'm using the PHP form builder class ( http://code.google.com/p/php-form-builder-class /) and i'm trying to
i am trying to valdiate the date field YYYYMMDD using PHP regex. I tried
I want to find all the demo words using PHP and regEx. $input ='demo';
Assuming the input string +123-321+123 345 , using PHP's regex functions I would like
Is there anyway to skip the first match when using regex and php. Or
I am trying to rewrite url from www.xxx.com/test.com to www.xxx.com/my.php?d=test.com using the following directive:

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.