Jump to content

Removing data between tags?


Solarpitch

Recommended Posts

Hey Guys,

 

I have a html page and I want to set some markers or tags so when I submit the page, I can strip out content between those tags.

For example something like

 

<!-- STRIP -->

.. html content la la la..

<-- END STRIP -->

 

or have a div with a class

<div class="strip">

... html content la la la

</div>

 

A. Which would be the best one?

B. How can I do this with ereg exp?

Link to comment
Share on other sites

Thanks guys but neither seem to work.. I tried:

 

$code = preg_replace('/<--STRIP-->.*?<--END STRIP-->/s', '', $this->input->post('content'));

 

$code = preg_replace('#<!--STRIP-->(.*)<--END -STRIP->#s', '', $this->input->post('content'));

 

Very strange.. the content is coming through and when I save the code to the database directly after this call, everything is still inside the tags.

Link to comment
Share on other sites

$string = 'Hey Guys,

I have a html page and I want to set some markers or tags so when I submit the page, I can strip out content between those tags.
For example something like

<!-- STRIP -->
.. html content la la la..
<-- END STRIP -->

or have a div with a class
<div class="strip">
... html content la la la
</div>

A. Which would be the best one?
B. How can I do this with ereg exp?';

$stripped = preg_replace('#<!-- STRIP -->(.*)<-- END STRIP -->#s', '', $string);

echo $stripped;

This example worked for me, although the ( brackets are not necessary.

 

Can you post your full code ?

Link to comment
Share on other sites

Actually,

 

I'm sending the post using Ajax where I need to escape() the html...

 

$(function() {
$(".save_newsletter").click(function() {

	var id = $(this).attr("id");
	var val = escape($("#content").html());
// escape
	var dataString = 'content='+ val;

	$.ajax({
		type: "POST",
		url: "<?php echo site_url(); ?>newsletter/save_newsletter/"+id,
		cache: false,
		data: dataString,
		success: function(html){
			$('.success').prepend(html);
		}
		});
	 return false;
});
});

 

This could be causing a problem?

 

EDIT: it must be, after it's escaped it sends through as .. 205px%3B%20border%3A%201px%20dashed% etc

But appears as normal in the database after the post and insert.

Link to comment
Share on other sites

 

Here's the code...

 

Save - submit call to Ajax

<a href="#" class="save_newsletter" id="<?php echo $template_id; ?>">Save</a>

 

 

Ajax - get html from <div class="content"></div>


$(function() {
$(".save_newsletter").click(function() {

	var id = $(this).attr("id");
	var val = escape($("#content").html());

	var dataString = 'content='+ val;

	$.ajax({
		type: "POST",
		url: "<?php echo site_url(); ?>newsletter/save_newsletter/"+id,
		cache: false,
		data: dataString,
		success: function(html){
			$('.success').prepend(html);
		}
		});
	 return false;
});
});

 

HTML - that was sent to the Ajax function from the content div with the tags


<!--STRIP-->
   <div id="product_list" style="display: none;">

<div style="width: 100%; float: left; font-family: Arial; font-size: 12px; padding: 5px; border: 1px dashed rgb(204, 204, 204); margin-bottom: 10px;">

		<div style="float: left; width: 200px;">23%u201D Automatic Umbrella</div>
		<div style="float: right; width: 150px;"><a href="#" class="link" id="25_3">Add to Newsletter</a></div>

	</div>

	<div style="width: 100%; float: left; font-family: Arial; font-size: 12px; padding: 5px; border: 1px dashed rgb(204, 204, 204); margin-bottom: 10px;">

		<div style="float: left; width: 200px;">A Ballylanders Rebel</div>
		<div style="float: right; width: 150px;"><a href="#" class="link" id="82_3">Add to Newsletter</a></div>

	</div>

	<div style="width: 100%; float: left; font-family: Arial; font-size: 12px; padding: 5px; border: 1px dashed rgb(204, 204, 204); margin-bottom: 10px;">

		<div style="float: left; width: 200px;">Automatic Umbrella (Tiger Woods)</div>
		<div style="float: right; width: 150px;"><a href="#" class="link" id="31_3">Add to Newsletter</a></div>

	</div>

	<div style="width: 100%; float: left; font-family: Arial; font-size: 12px; padding: 5px; border: 1px dashed rgb(204, 204, 204); margin-bottom: 10px;">

		<div style="float: left; width: 200px;">Black Labrador Soft Toy</div>
		<div style="float: right; width: 150px;"><a href="#" class="link" id="52_3">Add to Newsletter</a></div>

	</div>

	<div style="width: 100%; float: left; font-family: Arial; font-size: 12px; padding: 5px; border: 1px dashed rgb(204, 204, 204); margin-bottom: 10px;">

		<div style="float: left; width: 200px;">Children%u2019s Baking Set</div>
		<div style="float: right; width: 150px;"><a href="#" class="link" id="14_3">Add to Newsletter</a></div>

	</div>
</div>
<!--ENDSTRIP-->

 

 

PHP - Get posted code from Ajax and save to DB

public function save_newsletter()
{

	$code = preg_replace('#<!--STRIP-->(.*)<--ENDSTRIP-->#s', '', $post);

	$insert = array(
                'code' => $code,
	'client_id' => $this->session->userdata('client_id'),
	'client_uri' => $this->session->userdata('client_uri'),
               );

	$this->Newsletter_model->save_newsletter($insert);
}

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.