N
N
newdancer2015-12-10 12:43:13
PHP
newdancer, 2015-12-10 12:43:13

How to remove all contents of img tag except src?

How to remove all contents of img tag except src?
output json. The get_all_cinema.php file looks like this:

<?php
 
$response = array();

require 'db_connect.php';
 
$db = new DB_CONNECT();

$result = mysql_query("SELECT *FROM dle_post") or die(mysql_error());
 
if (mysql_num_rows($result) > 0) {
    $response["dle_post"] = array();
 
    while ($row = mysql_fetch_array($result)) {
        $cinema = array();
        $cinema["pid"] = $row["id"];
        $cinema["title"] = $row["title"];
        $cinema["category"] = $row["category"];
        $cinema["short_story"] = $row["short_story"];
        /*$cinema["xfields"] = $row["xfields"];*/
    
    $masxfields = array();
    $masxfields2 = array();
    $masxfields=split("\\|\\|", $row["xfields"], -1);
    for ($i = 1; $i <= count($masxfields); $i++) 
    { 
      $masxfields2=split("\\|", $masxfields[$i], 2);
      $cinema[$masxfields2[0]] = $masxfields2[1];
    } 
        array_push($response["dle_post"], $cinema);
    }
    $response["success"] = 1;

  $datastr=json_encode($response, JSON_UNESCAPED_UNICODE);/*кодируем в utf-8*/
  $datastr=stripslashes($datastr);/*убираем экранирование*/
  $datastr=strip_tags($datastr, '<img>');/*убираем теги кроме img*/

    echo $datastr;
} else {
    $response["success"] = 0;
    $response["message"] = "No cinema found";

    echo json_encode($response);
}
?>

an example of the output can be viewed on the page: kinoobzor.org/android/get_all_cinema.php
now the pictures are displayed like this
"screens":"<img src="http://kinoobzor.org/uploads/posts/2015-12/thumbs/1449526940-1892403274-1.jpg" alt='Любите Куперов (2015)' title='Любите Куперов (2015)'  /><img src="http://kinoobzor.org/uploads/posts/2015-12/thumbs/1449526940-97166829-2.jpg" alt='Любите Куперов (2015)' title='Любите Куперов (2015)'  /><img src="http://kinoobzor.org/uploads/posts/2015-12/thumbs/1449526941-1914472626-3.jpg" alt='Любите Куперов (2015)' title='Любите Куперов (2015)'  />"

and you need it like this:
"screens":"http://kinoobzor.org/uploads/posts/2015-12/thumbs/1449526940-1892403274-1.jpg, http://kinoobzor.org/uploads/posts/2015-12/thumbs/1449526940-97166829-2.jpg, http://kinoobzor.org/uploads/posts/2015-12/thumbs/1449526941-1914472626-3.jpg"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Skorik, 2015-12-10
@Omutik

Just form the url differently on the server side and pass the correct one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question