I am trying to extract php code from a php file (php file also contains html, css and javascript code). I am using the following regex for this
but this doesn't cater quotation marks (single and double quotes) and comments, i mean how can i skip php tags inside a string (and comments). Please have a look at the following code -
<?php
-
include("db.php");
-
$name=$_REQUEST['name'];
-
/* the regular expression to extract code inside php tags (i.e <? and ?>) is */
-
$str='|<\?[\w\W]*?\?>|';
-
# The regex can also be written using double quotes
-
$str="|<\?[\w\W]*?\?>|";
-
?>
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
-
<title>Sample PHP File</title>
-
</head>
-
-
<body>
-
<?="<h1>Some output from PHP?>
-
</body>
-
</html>
-
I need a regular expression that extracts the two blocks of PHP code from sample code
3 4104 Dormilich 8,658
Recognized Expert Moderator Expert @rizwan6feb
well, if I try, the RegEx gets it all. your problem is that it is extremely difficult to determine, whether a "?>" is a comment, a string or a processing instruction (i.e. you need to kind of parse the string).
maybe it's easier to do the reverse and not extract what's between ?> and <? (though this may also fail in special circumstances)
Dormilich 8,658
Recognized Expert Moderator Expert
are you sure? the RegEx fails for me (that is, it doesn't get the whole first block, only chunks).
translated into characters… all that's a string, a comment or any char - <\?("[^"]*?"|'[^\']*?'|/\*.*?\*/|.)*?\?>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: SamIAm |
last post by:
How do I extract the last 3 characters of a string i.e.
string s = "000001" I want "001"
Thanks,
S
|
by: Ori |
last post by:
Hi,
I have a HTML text which I need to parse in order to extract data from
it.
My html contain a table contains few rows and two columns. I want to
extract the data from the 2nd column in the most efficient way (using
Reg Ex.) either than using the "indexOf" function of String.
Thanks,
|
by: Thief_ |
last post by:
I've got this type of info on a web page:
----------------------------------------------------------------------------
--------------------------------------------
<tr height="25">
<td nowrap class="odd" align="center"><img
src="/forums/images/icon_topic_new.gif" width=14 height=14 alt='New Topic'
border=0></td>
<td nowrap class="odd" align="center"> </td>
|
by: kidkurious |
last post by:
I have a script that will read web file, extract the hyperlinks and sort them in alphabetical order.
It works fine, but not the way I want.
I want to change the script so that it will extract the text link as well.
//sortlinks.php
<?php
$matches= array();
|
by: Tony Girgenti |
last post by:
Hello.
Using VS.NET 2003 VB. If i have a string similar to the attached, how would
i extract the "Truckname=" data from it in a loop and stay in the loop until
the end of the string is reached ? As you can see the first truckname is
"284165". The next truckname is "284193"
Any help would be gratefully appreciated.
Thanks,
| |
by: teo |
last post by:
hallo,
I need to extract a word and few text that
precedes and follows it (about 30 + 30 chars)
from a long textual document.
Like the description that Google returns when
it has found a given word.
In example from:
|
by: Fabian Braennstroem |
last post by:
Hi,
I would like to delete a region on a log file which has this
kind of structure:
#------flutest------------------------------------------------------------
498 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04
8.3956e-04 3.8560e-03 4.8384e-02 11:40:01 499
499 1.0086e-03 2.4608e-04 9.8589e-05 1.4908e-04
|
by: GS |
last post by:
I need to extract sections out of a long string of about 5 to 10 KB, change
any date format of dd Mmm yyyy to yyyy-mm-dd, then further from each section
extract columns of tables.
what is the best approach in using regex for this? I can see match and
replace the dates, extract section with regex, and then for each section
extract again with the right regex the tables....
|
by: Ecka |
last post by:
Hi everyone,
I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that I end
up with a page that includes a lot of information that I don't need. Using
the PHP function strip_tags I've ended with the text below and from the
remaining HTML code, I'd like to extract the lines starting with "<TABLE
BORDER="1" WIDTH="315">" up to its closing </TABLEtag. How do...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |