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 6886573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:46:34+00:00 2026-05-27T05:46:34+00:00

I’m trying to grab the content from some Craigslist tags in PHP/Codeigniter. The tags

  • 0

I’m trying to grab the content from some Craigslist tags in PHP/Codeigniter. The tags I need to parse look like:

<!-- CLTAG xstreet0=Inman -->
<!-- CLTAG xstreet1=Moscrop -->
<!-- CLTAG city=Burnaby -->
<!-- CLTAG region=BC -->

For each one of these tags, which are contained in a $content variable, I’d like to grab each name/value pair. Tragically, I am the SUCK with regular expressions, but so far this at least finds the opening string of one of the tags:

$pattern = '/<!-- CLTAG city=/';
preg_match($pattern, $content, $matches);
echo "<pre>";
print_r($matches);
echo "</pre>";

Where I’m stuck is now to pull a pair of name/value out, so that I have ‘city’ and ‘burnaby’ to work with. Ditto for each of the others. I suspect a substr or something here?

  • 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-05-27T05:46:35+00:00Added an answer on May 27, 2026 at 5:46 am

    You can make your life a bit easier by including the “PREG_SET_ORDER” constant and preg_match_all() instead of preg_match() like so:

    $content = "
    <!-- CLTAG xstreet0=Inman -->
    <!-- CLTAG xstreet1=Moscrop -->
    <!-- CLTAG city=Burnaby -->
    <!-- CLTAG region=BC -->
    ";
    
    $pattern = '/<!--\sCLTAG\s([^=]+)=([^\s]+)\s-->/';
    preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
    
    foreach ($matches as $match) {
      echo 'key: ' . $match[1] . ' | value: ' . $match[2] . "\n";
    }
    

    If you encountered a scenario where no “xstreet1” value was specified (because addresses can work that way), you would need to slightly modify the regex pattern and add a check to ensure the second group exists in your loop:

    $pattern = '/<!--\sCLTAG\s([^=]+)=([^\s]+)?\s-->/';
    preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
    
    foreach ($matches as $match) {
      echo 'key: ' . $match[1] . ' | value: ';
      echo empty($match[2]) ? 'N/A' : $match[2];
      echo "\n";
    }
    

    Note how there’s a ‘?’ added after the second capture group in the regular expression. This tells the regex compiler that this group may or may not occur.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I would like to count the length of a string with PHP. The string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.