A
A
Anton2018-02-01 17:28:09
PHP
Anton, 2018-02-01 17:28:09

How to make a link?

<div id="div-name"></div> <!-- выведет ДДТ - Последняя осень -->
<?php
$s = file_get_contents("http://данные с сервера получаем по этому url");
?>
<script>
var myDiv= document.getElementById("div-name"), 
json = '<?php echo $s;?>',
data = JSON.parse( json );
myDiv.innerHTML = data.icestats.source.title;
</script>

The div-name displays the text - the author and the title of the song. I want to make a link and substitute the div-name data in this link.
Link looks like this
https://vk.com/search?c%5Bq%5D=Мумий%20Троль%20-%20дельфины&c%5Bsection%5D=auto

How to put this link in a div and substitute the track name in this link?
figuratively and bluntly speaking:
<a href="https://vk.com/search?c%5Bq%5D=<div 
id="div-name"></div>&c%5Bsection%5D=au
to"><div id="div-name"></div></a>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Grishaev, 2018-02-02
@Gigatrop

You have some strange approach. In a PHP variable you have JSON and it can be parsed by PHP itself and inserted immediately without javaScript. You will avoid the need for JS and any JSON escaping. Do everything in PHP, then creating a link will be much easier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question