pass preg replace variable to function - php

This is my function:
function bbc2html($content) {
$search = array (
'/(\[b\])(.*?)(\[\/b\])/',
'/(\[u\])(.*?)(\[\/u\])/',
'/(\[i\])(.*?)(\[\/i\])/',
'/(\[youtube\])(.*?)(\[\/youtube\])/'
);
$replace = array (
'<b>$2</b>',
'<u>$2</u>',
'<i>$2</i>',
'<div class="video_wrapper card border-0 shadow text-center m-2" style="width: 25rem;">
<div class="video_trigger card-body" data-source="'.getYoutubeVideoID('$2').'" data-type="youtube">
<p class="text-center">As soon as you click on the button you accept that cookies from YouTube to be loaded</p>
<input type="button" class="btn btn-success" value="OK">
<i class="fa-brands fa-youtube pe-1"></i>direct link
</div>
<div class="video_layer" style="display: none;">
<iframe src="" border="0" data-scaling="true" data-format="16:9" style="height: 0px;"></iframe>
</div>
</div>'
);
return preg_replace($search, $replace , $content);
}
function getYoutubeVideoID($link):string{
$baseUrl = parse_url($link, PHP_URL_HOST);
if($baseUrl == "youtu.be"){
$urlParts = explode('/',$link);
$id = end($urlParts);
} elseif (preg_match('/(youtube.com)/i',$baseUrl)) {
if(preg_match('/(youtube.com\/watch\?v=)/i',$link)){
$urlParts = explode('?v=',$link);
$id = end($urlParts);
} elseif(preg_match('/(youtube.com\/)/i',$link)) {
$urlParts = explode('/',$link);
$id = end($urlParts);
} else {
return "";
}
} else {
return "";
}
return $id;
}
I want to pass the variable ($2, contains the link to the youtube video) to the function (getYoutubeVideoID, returns only the id of the video), but it just pass '$2' instead of the link.
Example: [youtube] https://www.youtube.com/watch?v=LXb3EKWsInQ [/youtube]
This should be replaced with:
<div class="video_wrapper card border-0 shadow text-center m-2" style="width: 25rem;">
<div class="video_trigger card-body" data-source="LXb3EKWsInQ" data-type="youtube">
<p class="text-center">As soon as you click on the button you accept that cookies from YouTube to be loaded</p>
<input type="button" class="btn btn-success" value="OK">
<i class="fa-brands fa-youtube pe-1"></i>direct link
</div>
<div class="video_layer" style="display: none;">
<iframe src="" border="0" data-scaling="true" data-format="16:9" style="height: 0px;"></iframe>
</div>
</div>

The standard preg_replace doesn't allow you to execute a function on the replacement values, you can only pass literals with replacement placeholders.
You can get around this in multiple ways, however preg_replace_callback with that specific case might be the easiest to read. In the following code I also took the liberty of combining your first three shortcodes into a single one that uses a back-reference. I also removed captures that you we're using (for no good reason except to help me debug).
<?php
var_dump(bbc2html('[b]stuff[/b][youtube]abc[/youtube]'));
function getYoutubeVideoID($id)
{
// Just a demo function
return '!!'.$id.'!!';
}
function bbc2html($content)
{
$search = '/\[(b|u|i)]([^\[]*)\[\/\1]/';
$replace = '<$1>$2</$1>';
$newContent = preg_replace($search, $replace, $content);
return preg_replace_callback(
'/\[youtube](.*?)\[\/youtube]/',
static function ($matches) {
return '<div class="video_wrapper card border-0 shadow text-center m-2" style="width: 25rem;">
<div class="video_trigger card-body" data-source="'.getYoutubeVideoID($matches[1]).'" data-type="youtube">
<p class="text-center">As soon as you click on the button you accept that cookies from YouTube to be loaded</p>
<input type="button" class="btn btn-success" value="OK">
<i class="fa-brands fa-youtube pe-1"></i>direct link
</div>
<div class="video_layer" style="display: none;">
<iframe src="" border="0" data-scaling="true" data-format="16:9" style="height: 0px;"></iframe>
</div>
</div>';
},
$newContent
);
}
Demo: https://3v4l.org/0hkQj

Related

Delete button not working.. Error: Object not found

I am making an ecommerce website. So far, all are okay except where I want to delete items in the cart based on my cart database. The cart comprises of cart_id and menu_id.
Whenever I click the button (Delete), there is an error shown
"Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.52 (Unix) OpenSSL/1.1.1m PHP/8.1.2 mod_perl/2.0.11 Perl/v5.32.1"
I can't figure out what was my mistake. Hope you can help me. Thanks
<div class="container-2">
<?php
include('cart.php');
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isset($_POST['delete_submit'])) {
// call method addToCart
$Cart->deleteCart($_POST['menu_id']);
}
}
?>
<div class="row">
<div class="col h2 ">
<img src="https://logos-world.net/wp-content/uploads/2020/09/Starbucks-Emblem.png" class="Logo" alt="Logo" />
</div>
</div>
<div class="row" style="min-height: 20vh; border-top: 1px solid #dee2e6;">
<div class="col" style="text-align: left;">
<!-- Display Item From Database -->
<h3>Order here</h3>
<div class="row" style="padding: 1rem; background-color: #FFFFFF; border-radius: 10px; border: 1px solid #dfdfdf;">
<?php
foreach ($menu->getData('cart') as $item) :
$cart = $menu->getProduct($item['menu_id']);
$subTotal[] = array_map(function ($item) {
?>
<div class="col">
<div>
<img src="<?php echo $item['menu_image'] ?? "./menu-img/Warm Drinks/Brewed Coffee/Caffe ministo.jpeg"; ?>" style="width: 80%; border-radius: 25px;">
</div>
<div style="padding: 0.5rem;">
<h3>₱ <?php echo $item['menu_price'] ?? "0.00"; ?></h3>
</div>
</div>
<div class="col" style="margin: auto;">
<h5><?php echo $item['menu_name'] ?? "Unknown"; ?></h6><br>
</div>
<div class="col text-center" style="padding-top: 8%;">
<form action="post">
<input value="<?php echo $item['menu_id'] ?? 0; ?>" name="menu_id">
<?php
echo '<button type="submit" name="delete_submit" class="btn-default btn-lg"><p >Delete</p></button>';
?>
</form>
</div>
<!-- !cart item -->
<?php
return $item['menu_price'];
}, $cart);
endforeach;
?>
</div>
</div>
</div>
function:
public function deleteCart($menu_id = null, $table = "cart")
{
if ($menu_id != null) {
$result = $this->db->con->query("DELETE FROM {$table} WHERE menu_id={$menu_id}");
if ($result) {
header("Location:" . $_SERVER['PHP_SELF']);
}
return $result;
}
}
You have set the Form Element's action attribute to post. This attribute actually specifies the URL that the post data should be sent to. So instead of POSTing to the current URL, it's trying to send the data as a GET request (the default method) to http://yourdomain/post. What you need to do is set the method attribute instead and omit the action attribute.
<form method="post">
<button> Delete </button>
</form>

php class returns result with enter sign

so i have this code that gets an aray of rows from database, in order to put it in a
class dat{
public $result;
public function loadParteneri (){
global $db;
$nrcrt = 1;
$db->orderBy("numefirma","asc");
$parteneri = $db->get ("parteneri");
if ($db->count > 0)
foreach ($parteneri as $partener) {
$this->result[] = <<<EOD
<div id="{$partener['id']}" class="row lines">
<div class="col-md-1">{$nrcrt}</div>
<div class="col-md-2 serie">{$partener['numefirma']}</div>
<div class="col-md-1">{$partener['tippartener']}</div>
<div class="col-md-2">{$partener['cif']}</div>
<div class="col-md-2">{$partener['oras']}</div>
<div class="col-md-2">{$partener['nume']} {$partener['prenume']}</div>
<div class="col-md-2">
<span class="glyphicon glyphicon-search view-partener" title="Vizualizare"></span>
<span class="glyphicon glyphicon-trash trash-partener" title="Stergere"></span>
</div>
</div>
EOD;
$nrcrt++;
}
$db->disconnect();
}
}
than i call the class like this and send the response as json to ajax:
$response = new dat;
$response -> loadParteneri();
$response->result;
exit(json_encode($response));
problem is the response looks like this:
"<div id="97" class="row lines">
↵ <div class="col-md-1">1</div>
↵ <div class="col-md-2 serie">2 BRUNO MARS</div>
↵ <div class="col-md-1">clientfinal</div>
↵ <div class="col-md-2">RO15165473</div>
↵ <div class="col-md-2">HUNEDOARA</div>
↵ <div class="col-md-2"> </div>
↵ <div class="col-md-2">
↵ <span class="glyphicon glyphicon-search view-partener" title="Vizualizare"></span>
↵ <span class="glyphicon glyphicon-trash trash-partener" title="Stergere"></span>
↵ </div>
↵</div>"
what am i doing wrong? thanks in advance!
You could try to use str_replace:
$result = << EOD
// DIV's etc...
EOD;
$this->result[] = str_replace(["\n", "\r"], "", $result);
It is a bit hackish and replaces ALL the newlines in the result (Also between the DIV's).
You may want to consider using templates to separate you HTML and code instead of mixing it.

sending user a mesage by passing their id to a modal box

I am trying to create a message form into a bootstrap modal by Passing the user username/id to the modal for identification.
here is an html/php code that made a list of registered users.
<div class="col-lg-4 col-md-4 col-sm-4 mb">
<div class="content" style="margin-bottom:5px;">
<ul class=" extended inbox">
<div class="notify-arrow notify-arrow-green"></div>
<li>
<p class="green">People you can follow</p>
</li>
<?php
//Show all users
foreach ($users as $row) {
?>
<li style="padding:3px; margin-bottom:3px; width:100%; background:#CF9;">
<a href="index.html#">
<span class="photo" style="float:left; padding:4px;"><img alt="avatar" src="uploads/<?php echo $row['pix']; ?>" width="50" height="50"></span>
<span class="subject" style="float:left;">
<span class="from">
<?php
echo ''.$row['user_lastname']. ' '.$row['user_firstname'].'';
?>
<a class="" data-toggle="modal" data-target="#profile_pic_modal"><span class="glyphicon glyphicon-comment"></span></a>
</span><br>
<span class="time">
<?php
echo (($row['receiver'] === $row['user_id'] && $row['sender'] === $user_id)
? '<button class="btn follow following " rel="'.$row['user_id'].'">Following</button>'
:' <button class="btn follow" rel="'.$row['user_id'].'">
<i class="fa fa-user-plus alert-info"></i> Follow </button>');
?>
</span>
</span>
</a>
</li><br>
<?php
}
?>
</ul>
</div>
When a user click on another user's message icon he/she should be able to send message. Could someone please show me how to do this using php/mysqli and ajax
First add a data-(anyName) tag like below
<?php $ID = 'The persons Username'; ?>
<a href='#' class='btn btn-warning btn-xs open-AddBookDialog' data-id='$ID' data-toggle='modal'>My Modal</a>
Then put a input tag inside your modal body with a ID of example(MyID)
<input type="text" id="MyID">
Then using the code below (jquery) this will pass the value of data-id into that input tag on modal show.
$(document).on("click", ".open-AddBookDialog", function () {
var myId = $(this).data('id');
$(".modal-body #bMyID").val(myId);
$('#myModal').modal('show');
});
Information like username (login?) and id of a logged user should be disposed by Session, unlike you have good reasons for not do that. When the user enters in the system, you will already load a bunch of data to be sure he is valid, so the practical way to not retrieving always all the data from the user logged in, that are currently using your system, it's always good to use SESSIONs to handle that (imagine a ton of users using your system and you needing to retrieve each of them to each click and routine inside the system).
In a practical way, just open your modal and validate your routine using the started session with the user information settled in.
To clarify about the OTHERS users data (those listed that the current user will click to send a message) you can have to methods:
YOUR HTML:
<a href="#" data-userid='<?= $row['user_id']; ?>'>
<span class="photo" style="float:left; padding:4px;"><img alt="avatar" src="uploads/<?php echo $row['pix']; ?>" width="50" height="50"></span>
<span class="subject" style="float:left;">
<span class="from">
<?php
echo ''.$row['user_lastname']. ' '.$row['user_firstname'].'';
?>
<a class="" data-toggle="modal" data-target="#profile_pic_modal"><span class="glyphicon glyphicon-comment"></span></a>
</span><br>
<span class="time">
<?php
echo (($row['receiver'] === $row['user_id'] && $row['sender'] === $user_id)
? '<button class="btn follow following " rel="'.$row['user_id'].'">Following</button>'
:' <button class="btn follow" rel="'.$row['user_id'].'">
<i class="fa fa-user-plus alert-info"></i> Follow </button>');
?>
</span>
</span>
</a>
#Modal (Assuming you're using v4)
<div class="modal hide fade" id="user-message">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3 class="hdrtitle">Hey <?= $_SESSION['login']; ?>, Send message to <span></span></h3>
</div>
<div class="modal-body">
<label for='msg'>Message:</label>
<textarea id='msg' rows="4" cols="50" name='msg'></textarea>
<button id='send-msg'>Send Msg</button>
</div>
</div>
and then showing it with:
$('a').on('click', function(){
//retrieve all other user data
$.get( "yourcode.php?userid=" + $(this).data('userid'), function( data ) {
$('.modal h3 span').html(data.username);
//FILL YOUR MODAL AS YOU WISH
$('.modal').modal('toggle');
});
});
But the best way is to click and mount the modal in a partial view bringing the HTML already mounted with all information you want just to trigger the modal routine, avoiding html structure that the user don't really needs at first time access the page.
$('a').on('click', function(){
//retrieve all other user data
$.get( "partialmodal-sendmsg.php?userid=" + $(this).data('userid'), function( data ) {
$('body').append(data);
//FILL YOUR MODAL AS YOU WISH
$('.modal').modal('toggle');
});
});
Some must reads about:
When should I use session variables instead of cookies?
http://cse.unl.edu/~riedesel/pub/cse413/Project%202/SESSION.pdf

JQuery and PHP for dynamically created elements

Can somebody pls help me?
I'm currently working on a dynamic website. I have 2 navigations points and I have a video window on the right side. By clicking on one navigation point the respective video should appear in the video window. The problem is: my navigation list will be created dynamically and the video appearance as well (in this case the urls videos will be embedded from Youtube). Here is my PHP code where the list of navigation points will be created dynamically:
function reborn_videos($attribute){
ob_start();
$urls = $attribute['filme'];
$urls = explode(',', $urls);
?>
<div id="mobil_content">
<?php for($i=1; $i<= count($urls); $i++) {
$movie_title = $attribute['title'.$i];
?>
<div class="box">
<div class="box_title_video"><a class="expand"><?php echo $movie_title; ?> </a></div>
<?php foreach ($urls as $url) { ?>
<div class="box_body_iframe">
<iframe width="100%" height="315" src="https://www.youtube.com/embed/<?php echo trim($url); ?>" frameborder="0" allowfullscreen></iframe>
</div>
<?php } ?>
</div>
<?php } ?>
here is what i changed and looks right now:
function reborn_videos($attribute){
ob_start();
$urls = $attribute['filme'];
$urls = explode(',', $urls);
?>
<div id="mobil_content">
<?php for($i=1; $i<= count($urls); $i++) {
$movie_title = $attribute['title'.$i];
?>
<div class="box">
<div class="box_title_video"><a class="expand"><?php echo $movie_title; ?></a></div>
<div class="box_body_iframe">
<iframe width="100%" height="315" src="https://www.youtube.com/embed/<?php echo trim($urls[$i]); ?>" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<?php } ?>
and here the JQuery that I want to use to show and hide my videos:
var $alleVideos = $(".box_body_iframe");
function showVideos() {
$alleVideos.each(function(){
if ( $(this).hasClass('active') ) {
$(this).show();
} else{
$(this).hide();
}
});
}
$alleVideos.hide();
$(".box_title_video").click(function(){
$alleVideos.removeClass('active');
$(this).next().addClass('active');
showVideos();
});
in JQuery code i have no changes
this is how the Browser output the html code:
<div id="mobil_content">
<div class="box">
<div class="box_title_video">
<a class="expand">reborn</a>
</div>
<div class="box_body_iframe" style="display: none;">
<iframe height="315" frameborder="0" width="100%" allowfullscreen="" src="https://www.youtube.com/embed/7PnRkyu0HTs">
</div>
</div>
<div class="box">
<div class="box_title_video">
<a class="expand">trailer</a>
</div>
<div class="box_body_iframe active" style="display: block;">
<iframe height="315" frameborder="0" width="100%" allowfullscreen="" src="https://www.youtube.com/embed/">
</div>
</div>
</div>
The problem is: the JQuery animation just shows one and always the same video in the video window. :-(
The problem seems to be that you have a loop in your loop and both loops loop over all your urls:
for($i=1; $i<= count($urls); $i++)
...
foreach ($urls as $url)
So in every entry in the outer loop, you generate a list will all your videos. And you activate the first one of that list every time with $(this).next().addClass('active'); so you will always show the same, first, video.
You can probably solve your problem by replacing the inner loop with just the current item: $urls[$i]:
<div class="box_title_video"><a class="expand"><?php echo $movie_title; ?> </a></div>
<div class="box_body_iframe">
<iframe width="100%" height="315"
src="https://www.youtube.com/embed/<?php echo trim($urls[$i]); ?>"
frameborder="0" allowfullscreen></iframe>
</div>
</div>
Edit: I just noticed that your loop runs form 1 and arrays are zero-indexed, so you would need:
... src="https://www.youtube.com/embed/<?php echo trim($urls[$i - 1]); ?>" ...
^^^^^^^ here
Now you correctly show two blocks but as you can see in the second video, there is no url.

Remove all div tags from string php regex?

I have a wysiwyg on a site. The problem is that the users are copy pasting a lot of data in to it leaving a lot of unclosed and improperly formatted div tags that are breaking the site layout.
Is there an easy an easy way to strip all occurrences of <div> and </div>?
str_replace won't work because some of the divs have styling and other things in them so it would need to account for <div style="some styling"> <div align="center"> etc.
I'm guessing this could be done with a regular expression but I am total a total beginner when it comes to those.
Better to use DOM for HTML parser but if you have no choice but to use RegEx then you can use it like this:
$patterns = array();
$patterns[0] = '/<div[^>]*>/';
$patterns[1] = '/<\/div>/';
$replacements = array();
$replacements[2] = '';
$replacements[1] = '';
echo preg_replace($patterns, $replacements, $html);
No. You do NOT ever parse/manipulate HTML with regexes.
Regexes cannot be bargained with. They can't be reasoned with. They don't understand html, they don't grok xml. And they absolute will NOT stop until your DOM tree is dead.
You use htmlpurifier and/or DOM to manipulate the tree.
Here's a simplified example of how you could do it with PHP
<?php
/**
* Removes the divs because why not
*/
function strip_divs(&$text, $id = 'html') {
$replacements = array();
worker($text, $replacements, $id);
foreach ($replacements as $key => $val) {
$text = mb_str_replace($key, $val, $text);
}
return $text;
}
function worker(&$body, &$replacements, $id) {
static $call_count;
if (empty($call_count)) {
$call_count = array();
}
if (empty($call_count[$id])) {
$call_count[$id] = 0;
}
if (mb_strpos($body, '</div>')) {
$body = mb_str_replace('</div>', '', $body);
}
if (mb_strpos($body, '<di') !== FALSE) {
$call_count[$id] ++;
// Gets the important junk
$rm = '<di' . xml_get($body, '<di', '>') . '>';
// Builds the replacements HTML
$replacement_html = '';
$next_id = count($replacements);
$replacement_id = "[[div-$next_id]]";
$replacements[$replacement_id] = $replacement_html;
$body = mb_str_replace($rm, $replacement_id, $body);
if (mb_strpos($body, '<di') !== FALSE && $call_count[$id] < 200) {
worker($body, $replacements, $id);
}
}
}
/**
* Returns text by specifying a start and end point
*
* #param str $str
* The text to search
* #param str $start
* The beginning identifier
* #param str $end
* The ending identifier
*/
function xml_get($str, $start, $end) {
$str = "|" . $str . "|";
$len = mb_strlen($start);
if (mb_strpos($str, $start) > 0) {
$int_start = mb_strpos($str, $start) + $len;
$temp = right($str, (mb_strlen($str) - $int_start));
$int_end = mb_strpos($temp, $end);
$return = trim(left($temp, $int_end));
return $return;
}
else {
return FALSE;
}
}
function right($str, $count) {
return mb_substr($str, ($count * -1));
}
function left($str, $count) {
return mb_substr($str, 0, $count);
}
/**
* Multibyte str replace
*/
if (!function_exists('mb_str_replace')) {
function mb_str_replace($search, $replace, $subject, &$count = 0) {
if (!is_array($subject)) {
$searches = is_array($search) ? array_values($search) : array($search);
$replacements = is_array($replace) ? array_values($replace) : array($replace);
$replacements = array_pad($replacements, count($searches), '');
foreach ($searches as $key => $search) {
$parts = mb_split(preg_quote($search), $subject);
$count += count($parts) - 1;
$subject = implode($replacements[$key], $parts);
}
}
else {
foreach ($subject as $key => $value) {
$subject[$key] = mb_str_replace($search, $replace, $value, $count);
}
}
return $subject;
}
}
$html = <<<HTML
<table>
<tbody>
<tr>
<td class="votecell">
<div class="vote">
<input type="hidden" name="_id_" value="9607101">
<a class="vote-up-off" title="This question shows research effort; it is useful and clear">up vote</a>
<span itemprop="upvoteCount" class="vote-count-post ">0</span>
<a class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful">down vote</a>
<a class="star-off" href="#">favorite</a>
<div class="favoritecount"><b></b></div>
</div>
</td>
<td class="postcell">
<div>
<div class="post-text" itemprop="text">
<p>I have a wysiwyg on a site. The problem is that the users are copy pasting a lot of data in to it leaving a lot of unclosed and improperly formatted div tags that are breaking the site layout. </p>
<p>Is there an easy an easy way to strip all occurrences of <code><div></code> and <code></div></code>?</p>
<p>str_replace won't work because some of the divs have styling and other things in them so it would need to account for <code><div style="some styling"> <div align="center"></code> etc</p>
<p>I'm guessing this could be done with a regular expression but I am total a total beginner when it comes to those. </p>
<p>Thanks a lot,
Martin
</p>
</div>
<div class="post-taglist">
php regex replace str-replace strip-tags
</div>
<table class="fw">
<tbody>
<tr>
<td class="vt">
<div class="post-menu">share<span class="lsep">|</span>improve this question</div>
</td>
<td align="right" class="post-signature">
<div class="user-info ">
<div class="user-action-time">
edited <span title="2012-03-07 18:32:29Z" class="relativetime">Mar 7 '12 at 18:32</span>
</div>
<div class="user-gravatar32">
</div>
<div class="user-details">
<div class="-flair">
</div>
</div>
</div>
</td>
<td class="post-signature owner">
<div class="user-info ">
<div class="user-action-time">
asked <span title="2012-03-07 18:31:11Z" class="relativetime">Mar 7 '12 at 18:31</span>
</div>
<div class="user-gravatar32">
<a href="/users/702826/martin-hunt">
<div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/a578c3eae229c86dbe46d4b1603e071b?s=32&d=identicon&r=PG" alt="" width="32" height="32"></div>
</a>
</div>
<div class="user-details">
Martin Hunt
<div class="-flair">
<span class="reputation-score" title="reputation score " dir="ltr">313</span><span title="7 silver badges"><span class="badge2"></span><span class="badgecount">7</span></span><span title="20 bronze badges"><span class="badge3"></span><span class="badgecount">20</span></span>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td class="votecell"></td>
<td>
<div id="comments-9607101" class="comments ">
<table>
<tbody data-remaining-comments-count="0" data-canpost="false" data-cansee="true" data-comments-unavailable="false" data-addlink-disabled="true">
<tr id="comment-12187969" class="comment ">
<td class="comment-actions">
<table>
<tbody>
<tr>
<td class=" comment-score">
<span title="number of 'useful comment' votes received" class="cool">1</span>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</td>
<td class="comment-text">
<div style="display: block;" class="comment-body">
<span class="comment-copy">So you need to remove all the div tags but not the content between the div. Am I right?</span>
– Siva Charan
<span class="comment-date" dir="ltr"><a class="comment-link" href="#comment12187969_9607101"><span title="2012-03-07 18:34:11Z" class="relativetime-clean">Mar 7 '12 at 18:34</span></a></span>
</div>
</td>
</tr>
<tr id="comment-12189778" class="comment ">
<td>
<table>
<tbody>
<tr>
<td class=" comment-score">
</td>
<td>
</td>
</tr>
</tbody>
</table>
</td>
<td class="comment-text">
<div style="display: block;" class="comment-body">
<span class="comment-copy">Replace the XPath with <code>//div[not[#*]]</code> to remove all div elements (incl. content) without attributes.</span>
– Gordon
<span class="comment-date" dir="ltr"><a class="comment-link" href="#comment12189778_9607101"><span title="2012-03-07 19:58:21Z" class="relativetime-clean">Mar 7 '12 at 19:58</span></a></span>
<span class="edited-yes" title="this comment was edited 2 times"></span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="comments-link-9607101" data-rep="50" data-anon="true">
<a class="js-add-link comments-link disabled-link " title="Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.">add a comment</a><span class="js-link-separator dno"> | </span>
<a class="js-show-link comments-link dno" title="expand to show all comments on this post" href="#" onclick=""></a>
</div>
</td>
</tr>
</tbody>
</table>
HTML;
echo strip_divs($html);

Categories