473,799 Members | 3,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preg_match and Preg_replace trouble regular expressions Please HELP!

need to extract all text between the following strings, but not
include the strings.
"<!-- #BeginEditable "Title name" -->"
"<p align="center"> #### </p>"
I am using preg_match(???? , $s, $results)
but I have had no success. I tried items like.. "<!-- #BeginEditable
"Title name" -->".*."<p align="center"> #### </p>"
But have had no luck.
Please any assistenc is appreciated.
In addition, I need to use preg_replace to replace the following:
<a href="/folder2/folder1/folder/*page.html">
with
<a href="site.com= page.php?option *=paper&itemid= page.html">
Again, any help is appreciated. The regular expressions confuse me, my

brain is about to explode from all the trouble shooting, I guess I'm
just not smart emough to figure it out.
PLEASE HELP!!
thanks

Aug 1 '05
22 2776
I was reviewing the code again, and correct me if I'm wrong, from what
I understand the current code only replaces.....

<a href="/folder2/folder1/folder/ page.html">

with

<a href="site.com= page.php?option =paper&itemid=p age.html">

if it's between each occurance of the preg_match.

I was trying to do two totally seperate items.

1) find one distinct pregmatch on a single page

2) replace links within a page

But as stated, they are totally independent.

If this simplifies matters, I can still use the help.

thanks again.

I've been working on this all morning, but am not having any luck.

thanks

Aug 6 '05 #11
I decided to focus on one item at a time. This is what I have so far,
but I get the following error...

Warning: Unknown modifier '(' in /Users/imac/Sites/folder/test.php on
line 17

when using the following code....

<?php
// i find it easier to remember two calls to ini_set
//ini_set('error_ reporting', E_ALL);
// make sure they are displayed
ini_set('displa y_errors', TRUE);

//replace "news.htm" with your file
$s=implode('', file("http://www.site.com/test.php"));

$pattern="<!-- #BeginEditable \"Title of Firmrecall\" -->(.*?)<p
align=\"center\ ">#### </p>";
if(preg_match($ pattern, $s, $results)){

echo $results[0];

}
?>

Aug 6 '05 #12
this is line 17

$pattern="<!-- #BeginEditable \"Title of Firmrecall\" -->(.*?)<p
align=\"center\ ">#### </p>";

Aug 6 '05 #13
I'm begging for someone to help me out here. I've been working at this
non stop for the last for days, and I and not find a solution to my
problem.

This is the pattern I'm using to find everything between...

"<!-- #BeginEditable "Title of name" --> " AND "<p
align="center"> #### </p>"
$pattern="/<\!-- #BeginEditable \"Title of Firmrecall\" -->.*<p
align=\"center\ ">#### </p>/i";

But I get nothing.

PLEASE HELP!!!!

Aug 6 '05 #14
Somebody wrote:
$pattern="/<\!-- #BeginEditable \"Title of Firmrecall\" -->.*<p
align=\"center\ ">#### </p>/i";


a) Encode/escape the slash in your pattern; e.g., /<\/p>/.

b) Use different delimiters; e.g., `...`.

[Just probing, but why have you set the i modifier?]

--
Jock
Aug 6 '05 #15
I tried changing it, but still not luck, can you post what you mean?

I tried many varations, but my last was...

$pattern="'/<\!-- #BeginEditable \"Title of Firmrecall\" -->/.*/<p
align=\"center\ ">#### /<\/p>/'";

I had the i to make the text case insensitive, but it's really not
nessesary I guess.

Aug 6 '05 #16
Somebody wrote:
$pattern="'/<\!-- #BeginEditable \"Title of Firmrecall\" -->/.*/<p
align=\"center\ ">#### /<\/p>/'";


$pattern="/<\!-- #BeginEditable \"Title of Firmrecall\"
-->.*<p align=\"center\ ">#### <\/p>/";

--
Jock
Aug 7 '05 #17
still no luck, so I decided to take it one piece at a time and find out
which part it the problem.

I think it might have some thing to do with "<"

I tried

preg_match("/<h.t/", "<hat", $results)
echo $results[0];

and it did not work.

I changed it to...
preg_match("/h.t/", "hat", $results)
echo $results[0];

and it did work. So I thought ok just escape the "<" character with..
preg_match("/\<h.t/", "<hat", $results)
echo $results[0];

but no luck, any ideas why?

thanks

Aug 7 '05 #18
Somebody wrote:
preg_match("/\<h.t/", "<hat", $results)
echo $results[0];

but no luck, any ideas why?


Sure, you're relying on your browser to tell you the results
and it's hiding them from you. Your browser likely interprets
the string '<hat' as the beginning of a tag. Look at the
source and see what results you actually get.

--
Jock
Aug 7 '05 #19
OK, I'm getting closer but still having trouble.

does any one know why the preg_match stops the match if the string goes
to the next line.

for example....

//replace "news.htm" with your file
$s=implode('',
file("http://www.fda.gov/oc/po/firmrecalls/perrigo07_05.ht ml"));

//echo $s;

preg_match("/\"Title of Firmrecall\".*/",$s,$resul t);

echo $result[0];

displays....
"Title of Firmrecall" The following is the title and

When it should be
"Title of Firmrecall" The following is the title and
this is the next line of the title.
But the "this is the next line of the title" and everything after it
does not get displayed.

PLEASE HELP!!! I've been working at this non stop but can not get it
working, I'm disperate!!!

Aug 7 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4899
by: Juha Suni | last post by:
Hi! I have managed to live without using too much regular expressions so far, and now that I need one, I need some help too. I have a string containing a (possibly large) block of html. I need to insert code (an image to be precise) right after the last textual character in the string. This is, of course, no problem if the end contains plain text and no html. If the string ends in HTML however, I need to fiddle around. for example...
3
2824
by: Marco Snoek | last post by:
Hi, Hope you can help me out with this one.. nl2br($string) converts all the \n to <br \> ... but .. Suppose I have a table or other HTML elements in $string.. All the TD> and TR> and FORM> are trailed by <br />
2
4461
by: pomho | last post by:
Hi all, Even having read the PHP Manual, I can't understand the difference between the ereg function and the preg_match... Could anyone help ? thx in advance, --
14
7184
by: Westcoast Sheri | last post by:
What is the most efficient way of extracting the first two digits in a string? The following is wrong for me, because it only gives me the first instance of two digits together: $string = ujdk3ca94abc preg_match("/\d{2}/",$string,$result); echo "$result"; //prints 94. However, the result I am looking for is 39
2
8559
by: Muumac | last post by:
I have problem with large textfiles! When I load over 4MB xml and then try to preg_match something in this I get always FALSE! I have <File>....</File> tags in XML. Between tags is files contents BASE64 encoded! When xml contains only one big over 4MB file in it, preg_match and preg_match_all doesnt find it! When included file size is nelow 4MB, preg functions works perfectly! But PHP manual says that there is no size limitations to...
16
2893
by: bissatch | last post by:
Hi, I am trying to use preg_replace to take out all occurances of PHP code after reading (fread()) the contents of a PHP file. The code I am using is: $html = preg_replace("<?php*?>", "", $html); Unfortuntely it is not working and giving the following error:
4
13978
by: Clodoaldo Pinto | last post by:
preg_match(): Compilation failed: regular expression too large at offset 0 The regular expression is 34,745 bytes long. <?php $regExp = 'huge regexp with 34,745 bytes'; echo '<pre>strlen($regExp) = ', strlen($regExp), "\n"; echo preg_match($regExp, 'sudokusweb.com'); echo '</pre>';
3
1015
by: Silvertype | last post by:
Hi guys, I have these html tags: <input type="text" id="txtName" name="txtName" /> <textarea id="taHello" name="taHello">hello world</textarea> which I want to replace with the following tags:
13
5375
by: chadsspameateremail | last post by:
I might have found a problem with how preg_match works though I'm not sure. Lets say you have a regular expression that you want to match a string of numbers. You might write the code like this: preg_match( '/^+$/', $TestString ); OK everything seems fine. However, did you know if you pass the following to preg_match: "12345\n" it will return that a match occurred?!? Even though the newline is not a valid character in our regular...
0
9546
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,...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10031
tracyyun
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...
0
9079
agi2029
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...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.