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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:15:49+00:00 2026-05-13T16:15:49+00:00

I am creating a project, and I need to be able to use a

  • 0

I am creating a project, and I need to be able to use a regex(or if something else is preferable?)

Basically, I need to convert a PHPish markup code page so that the “non-code” is converted into “code.” For instance:

Orginal:

<?code
  echo 'some text';
?>
<head>
</head>
<body>
</body>
<?code
  echo '</html>';
?>

Converted:

<?code
  echo '<html>';
  echo '
<head>
</head>
<body>
</body>';
  echo '</html>';
?>

How could this work while also taking quotes into account? (like <?code $var='<?code stuff ?>';?>

Also, if someone provided me with something to detect included files, (to replace with something that first “prepossesses” the file then includes it) (where the includes are similar to PHP)

Is this even possible with Regex? I know your not suppose to try to parse HTML with regex, but this isn’t trying to parse it, it’s really being quite dumb to how the markup and everything is..

Also, this project will actually be implemented in Ruby(the preprocessor that is), so if there is something Ruby has that would aid in this, then have at it.

I know the code looks very similar to PHP, but thats because it is, but it will not be implemented in PHP and the “code” used won’t actually be PHP, but it will use a <? type mechanism for containing code in markup.

Edit: also note that the language inside the markup can for all practical purposes be Ruby. So it can contain quotes and comments that have the closing code tag.

  • 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-13T16:15:49+00:00Added an answer on May 13, 2026 at 4:15 pm

    You can use token_get_all to get a stream of parser tokens. Loop through them and echo them out, when you come upon a T_INLINE_HTML, you can then rewrite it to an echo statement instead.

    Edit – Just saw you say you’re using Ruby. Obviously, you can’t use PHP’s tokeniser from within Ruby. Maybe you can call php over the command line?

    Edit 2:

    Is this even possible with Regex? I know your not suppose to try to parse HTML with regex, but this isn’t trying to parse it, it’s really being quite dumb to how the markup and everything is..

    It’s parsing alright. You can use regexp to split your input into tokens (aka tokenization). Since most languages are contextual, you will then have to feed the tokens to a state machine, which can parse the code into an internal representation (an AST). This can then be transformed into your target output. It sounds elaborate and scary, but it’s really quite simple when you have tried it a couple of times. I suggest that you work through it, with the help of Wikipedia and Google.

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

Sidebar

Related Questions

What are the necessary items need from creating a deployment project for a windows
in the project I'm creating I need to check if the user is logged
I need to build a project programmatically for a .csproj I am creating on
I'm creating a project to house an iPhone library for common code for the
I have a bunch of code in an iOS project (named MyLibs) I re-use
I'm coming from a Opengl project and I need to be able to place
I'm currently working on a web-project where we need to be able to get
For a customer project, I need to be able to add/remove tags from items
Writing a program for a project. I need to use a ListSelectionListener in order
I need to learn more about creating setup projects from within Visual Studio to

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.