Dear Buddies,

Need your help to make a simple regex to grab all codes from <!-- Begin Code --> until <!-- End Code -->

I would like capture this code for deleting in Yahoo pipes.

code:

<!-- Begin Code -->
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: '132829708015487', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>


	
		
		
		
	
				


<ul id="socialTools">
<li class="twitter">

<script type="text/javascript">
tweetmeme_style = 'compact';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>
</li>
<li class="digg">

<script type="text/javascript">
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.src = 'http://widgets.digg.com/buttons.js';
s1.parentNode.insertBefore(s, s1);
})();
</script>
<a href="http://digg.com/></a>
</li>
<li class="buzz">

<span>
<a title="Post on Google Buzz" class="google-buzz-button"></a>
<script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script>
</span>
</li>
<li class="facebook">

<fb:like href="" />
</li>
</ul>

<div style="clear: both;"></div>
<!-- End Code -->

Thanks for your kind help.

Best Regards,

Recommended Answers

All 9 Replies

if (preg_match('/<!-- Begin Code -->(.*?)<!-- End Code -->/s', $subject)) {
	# Successful match
} else {
	# Match attempt failed
}
if (preg_match('/<!-- Begin Code -->(.*?)<!-- End Code -->/s', $subject)) {
	# Successful match
} else {
	# Match attempt failed
}

Thanks for your kind help, but I'm very dumb about this. I tried this in gskinner.com, but I can't find the capturing result. Can you give an example code that I must fill in 1stbox of gskinner.com, to get a capturing result?

Many thanks and best regards.

If you want to delete the text from the stream but still have the contents. I simulated the feed with a file from your code that I made called subject.php.

<body>
<?php
$subject = file_get_contents('subject.php');
$mark=preg_replace('/<!-- Begin Code -->(.*?)<!-- End Code -->/s', $subject,'');
echo("Mark is ".$mark."<br />" .$subject);
?>
</body>
</html>

Your regex contains spaces, and may not work. The space may not be there.

You know, I didn't check that. I just used his file. Life becomes very different when the script goes live. Who knows whether all the pages are exactly the same(made with a template) or not. One example does not make a regex as you point out. Did you try his code @pritaeas?

pritaeas and tinymark, thanks for your kind help.. I'm still confuse to apply it in Yahoo Pipe... usually I use hxxp://gskinner.com/RegExr/

regards,

I think I get the whole picture now. Pipes allow you to select a lot of different news feeds and process them with their filters. The whole mess gets put together into a personalized feed that would be a clickable thing if I had an account and was at the site. You want to setup your pipes at Yahoo because you have an account and want to use Ajax, PHP something to go get the feed information and save it to a variable in your program. Then you want to apply some local filters to get rid of the stuff you have downloaded that you don't want to see. Now ask me if I use news feeds.:P

In jquery I would go something like this.

$.post('http://pipes.yahoo.com/pipes/pipe.run?_id=Kt...y0Q&_render=rss&_run=1&locationinput1=richmond%2C+va', function(data){
if (data) var my_data = data;
further_processing(data); });
function further_processing(data){
'finish the processing with a regex'
}

I hope that helps. Didn't know a thing about them before I started. Some of the people I know kid me about not using news readers.

I think I get the whole picture now. Pipes allow you to select a lot of different news feeds and process them with their filters. The whole mess gets put together into a personalized feed that would be a clickable thing if I had an account and was at the site. You want to setup your pipes at Yahoo because you have an account and want to use Ajax, PHP something to go get the feed information and save it to a variable in your program. Then you want to apply some local filters to get rid of the stuff you have downloaded that you don't want to see. Now ask me if I use news feeds.:P

That's right, I would delete all code as above. The problem is that I failed to capture all code from <!-- Begin Code --> to <!-- End Code -->.. :) Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.