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 22 2775 st*****@hotmail .com wrote: 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>"
Try something like '/Title name" -->(.*)<p align="center/' for the
regex, and look for the answer in $results[1].
When you attempt to learn regexes, empty your mind of everything you
know from PHP or other computer languages. The parens, dot, star, and
other special characters are used in completely different ways than in
procedural languages.
Here's a quick link to PHP man: http://us2.php.net/manual/en/function.preg-match.php
Here's a toot that others have found useful: http://weblogtoolscollection.com/regex/regex.php
(myself, I learned regex back in the day of awk, when all we had was
woodburning computers)
<snip>
In addition, I need to use preg_replace to replace the following:
<snip>
Well, you'll probably want something along the lines of
$newString = preg_replace('/OldStuff/', "NewStuff", $oldString);
but check out a tutorial or two to get a handle on all this 'stuff'.
Friedl's _Mastering Regular Expressions_ is a good book on the subject.
It is not a light read. But then regular expressions are really a
computer language of their own, embedded into languages like PHP and
Perl, but with their own separate syntax and rules.
The regular expressions confuse me, my brain is about to explode from all the trouble shooting
Yeah, been there. Wish you luck.
Thank you for the responses, I'm going to try this stuff tonight and I
hope it works.
thanks
Regular Expressions are great. Less than 10 lines of code can be so
powerful when you start to grasp the technology.
=============== =============
<?
$fp=fopen("preg test.txt","r+") ;
$content=fread( $fp,filesize("p regtest.txt"));
fclose($fp);
echo "\n\nBEFORE :\n------------------\n";
echo $content;
preg_match_all( "|<a href=\".+\">|m" ,$content,$matc hes);
foreach($matche s[0] as $value)
{
preg_match("|\" .+/([^/]+)\">$|",$value ,$page);
$pattern="(.+<!-- #BeginEditable \"Title name\" -->.+)" . $value .
"(.+<p align=\"center\ ">#### </p>.+)";
$replacement="< a href=\"site.com =page.php?optio n*=paper&itemid =" .
$page[1] . "\">";
$content=preg_r eplace("|$patte rn|s","\${1}" . $replacement .
"\${2}",$conten t);
}
echo "\n\nAFTER: \n------------------\n";
echo $content . "\n\n";
?>
HERE IS THE OUTPUT:
-------------------------------------------------
BEFORE:
------------------
some content that I don't want to edit...
<a href="/folder9/folder8/folder7/-page555.html">
<!-- #BeginEditable "Title name" -->
<a href="/folder2/folder1/folder/*page.html">
<a href="/folder9/folder8/folder7/-page555.html">
<p align="center"> #### </p>
More content that I don't want to edit...
<a href="/folder2/folder1/folder/*page.html">
AFTER:
------------------
some content that I don't want to edit...
<a href="/folder9/folder8/folder7/-page555.html">
<!-- #BeginEditable "Title name" -->
<a href="site.com= page.php?option *=paper&itemid= *page.html">
<a href="site.com= page.php?option *=paper&itemid=-page555.html">
<p align="center"> #### </p>
More content that I don't want to edit...
<a href="/folder2/folder1/folder/*page.html">
cameron7,
Thank you for your post. But I'm still having trouble. I think your
complicating what I'm trying to do. When I tried your code, nothing
appeared on the page. I assume, there is a syntax error, but I may be
wrong. I've tried debugging, with no luck. You included a loop
through for each apearance of the pattern, but in my pages it only
occurs once. Basically I'm removing an old header and footer, and
replacing old links with a new path from the existing page. I
appreciate you helping me.
thanks
Ok, I am getting closer but still no solution. I figured out your code
had extra spaces, most likely a google thing, but I removed them and
now I get the before part but the after section is blank. Any ideas?
thanks
Ok, sorry for all the extra posts, but I wanted to fill you in on where
I am.
When I use....
$fp=fopen("http ://www.site.com/pregtest.html", "r+") ;
$content=fread( $fp,filesize("h ttp://www.site.com/pregtest.html") );
fclose($fp);
etc. etc.
I get .....
"Before---------------After----------------", but that is it, no other
content.
If I change it to ...
$content=implod e('', file("http://www.site.com/pregtest.html") );
etc.etc..
I get .....
"Before---------------------
....ALL NORMAL CONTENT......"
But then nothing under After, nor do I see the "AFTER"
I am so lost I want to bang my head against a wall, I don't know much
programming and this stuff is way over my head.
thanks, any assistence is apprecaited.
<?
error_reporting (E_ALL);
/* INSERT CODE HERE */
?>
On 2005-08-06, cameron7 <ca******@gmail .com> wrote: <?
error_reporting (E_ALL);
// 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);
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be >
I added the
// 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);
line and when I use....
$fp=fopen("http ://www.site.com/pregtest.h tml","r+") ;
$content=fread( $fp,filesize("h ttp://www.site.com/pregtest.h tml"));
fclose($fp);
etc. etc.
I get .....
"Warning: fopen() expects at least 2 parameters, 1 given in
/Users/imac/Sites/folder/test.php on line 8
Warning: filesize(): Stat failed for http://www.site.com/test.php
(errno=2 - No such file or directory) in
/Users/imac/Sites/folder/test.php on line 9
Warning: fread(): supplied argument is not a valid stream resource in
/Users/imac/Sites/folder/test.php on line 9
Warning: fclose(): supplied argument is not a valid stream resource in
/Users/imac/Sites/folder/test.php on line 10
BEFORE: ------------------ AFTER: ----------------- -"
But, If I change it to ...
$content=implod e('', file("http://www.site.com/pregtest.h tml"));
etc.etc..
I get .....
"Before---------------------
....ALL NORMAL CONTENT......"
Fatal error: Maximum execution time of 30 seconds exceeded in
/Users/imac/Sites/Folder/test.php on line 31 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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 />
|
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,
--
|
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
|
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...
| |
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:
|
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>';
|
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:
|
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...
|
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: 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: 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: 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();...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |