Quantcast
Channel: Question and Answer » json
Viewing all articles
Browse latest Browse all 148

Search and replace image src from JSON [on hold]

$
0
0

I am trying to write a simple module that will check nodes and if a node has field “body” to execute the str function and change default drupal root sign to $base_url.
This is what I tried, but it doesn’t work. I would appreciate any help. I am not even sure if the syntax is right nor should I be aiming at the ‘node’ object.

function search_replace_preprocess_node(&$variables) {
dpm($variables);
    if (in_array("body", $variables['node']->'values')) {
        str_replace("src='", "src=$base_url", "src='");
    }

}

This is what I get in json that drupal generates which I am trying to use:

src=”/sites/default/files/inline-images/example.jpg”

It generates an error that looks like this:
GET
http://localhost/sites/default/files/inline-images/example.jpg [HTTP/1.1 404 Not Found 1ms]

I want to create absolute path instead of this “localhost” part, cuz I am trying to use img src on another site which is located on another url.


Viewing all articles
Browse latest Browse all 148

Latest Images

Trending Articles



Latest Images