Php add link to head

Как передать информацию в head через php?

Всем привет, помогите пожалуйста решить проблему.
Сейчас всё подробно опишу и в конце предоставлю полный код целиком.

Есть первый php код который находится в body:

.xml"); $data = array(); preg_match_all('/.*?/m', $text0, $out1); preg_match('/img src="https://qna.habr.com/q/(.*?)"/m', $text0, $out3); preg_match('/img src="https://qna.habr.com/q/(.*?)"/m', $text0, $out4); $out3 = preg_replace("#http://(www\.)?(.*?)/#is", '', $out3); $out3 = preg_replace("#([^/]*)$#", '', $out3); $out4 = preg_replace("/\?.*/", '', $out4); $out4 = preg_replace("/.*?\./", '', $out4); ?>

Данный код берёт из файла xml ссылку на нужное мне изображение, пилит её на части как мне нужно, и выдаёт их с помощью print_r

print_r $out3[1] выводит 1/amazing/029/
print_r $out4[1] выводит png
В итоге получается ссылка на картинку 1/amazing/029/1.png

Далее я ещё много где использую print_r но всё это после основного php скрипта.
А сейчас мне необходимо эту же ссылку передать в head сайта в мета теги.

Придумал примерно вот такой выход, через php передать информацию до отрисовки страницы. Это второй код:

 //данную часть я размещаю в head сайта в мета теги 1.'; return $testphpcode; > ?>

Это работает, но проблема в том, что передаётся не 1/amazing/029/1.png а само 1. в текстовом виде.

Вот так выглядит полный код:

 "> "> "> // Данный php код трогать и менять нельзя, слишком поздно его менять. .xml"); $data = array(); preg_match_all('/.*?/m', $text0, $out1); preg_match('/img src="https://qna.habr.com/q/(.*?)"/m', $text0, $out3); preg_match('/img src="https://qna.habr.com/q/(.*?)"/m', $text0, $out4); $out3 = preg_replace("#http://(www\.)?(.*?)/#is", '', $out3); $out3 = preg_replace("#([^/]*)$#", '', $out3); $out4 = preg_replace("/\?.*/", '', $out4); $out4 = preg_replace("/.*?\./", '', $out4); ?> // Этот php код менять можно. 1.'; return $testphpcode; > ?> 

Помогите изменить второй скрипт так, чтобы передавалось это 1/amazing/029/1.png
Сразу говорю, первый php код переместить в head сайта не представляется возможным.

Источник

Adding to Using php

Doomer 65

You cannot access Absolute URL in include function.

Relative Paths

index.html

/graphics/image.png

/help/articles/how-do-i-set-up-a-webpage.html

Absolute Paths

The first difference you’ll notice between the two different types of links is that absolute paths always include the domain name of the website, including http://www., whereas relative links only point to a file or a file path. When a user clicks a relative link, the browser takes them to that location on the current site. For that reason, you can only use relative links when linking to pages or files within your site, and you must use absolute links if you’re linking to a location on another website.

Ravi Hirani 6361

More Answer

  • Drupal adding «add new» link using PHP code
  • Adding multiple buttons to a cart using php
  • Parsing 2 head json and grouping using php
  • simulate a link call using php code
  • Get url of a website and convert html page of that link to PDF using PHP
  • Detecting if href link is clicked using PHP
  • Adding advertisement to android application using php file
  • adding up return values from function using php
  • Retrieve specific link values form tag using php simple_html_dom.php
  • Retrieve specific link values form tag using php simple_html_dom.php
  • How to open a windows folder when clicking on some link on a HTML page using PHP
  • Dynamically adding content to HTML document using PHP
  • adding headers to csv from sqlite3 using php
  • adding headers to csv from sqlite3 using php
  • adding comments using php and html
  • extracting a link in a html table php using simple_html_dom
  • Php and Drupal: how do I hide/display my link when needed using php within Drupal?
  • How do I add a link into an xml tag using php
  • Adding multiple fields to DB using PHP
  • PHP — Using DOMDocument — trying to find link to feed
  • Refresh jQuery Mobile elements after adding them to the page using AJAX and PHP
  • Using PHP Sub String to Link Thumbnails
  • PHP — Using preg_replace to put http:// before link
  • How to open a link using Jquery from HTML, getting the URL from MySql and PHP
  • Adding Dynamic navigation link with PHP for Buddypress/Wordpress
  • Facing Warnings LDAP using PHP wrong link resource
  • Check the authenticity of given link and store it in a mysql table using php
  • What is the best practice for adding a template into a page using PHP and jQuery AJAX
  • Adding using HTML forms and PHP
  • Adding numbers using HTML forms and PHP
  • Adding php code to a url link
  • Adding php code to a url link
  • Adding events to google calendar using php without login by more than one user
  • xml parser using php from a link
  • Trying to run a query using a PHP cURL session and adding for a loop inside PHP
  • Download link to download XML file using href in PHP
  • How to link html table to mysql table using PHP
  • Adding a newline / (carriage?) return in Excel using PHP
  • Adding a newline / (carriage?) return in Excel using PHP
  • Updating MongoDB using PHP simplexml_load_string function variables adding extra ‘0’ key to value
  • Find url and link text from string using php code
  • How to retrieve link location using preg_match in PHP
  • rtmp link video url thumbnail generate using php
  • Adding a facebook page tab using php
  • Automatically link words using PHP
  • ID is not shown if using header in PHP instead of usual HTML link
  • Link using a PHP Variable
  • How to include a css link in hidden input using PHP
  • Adding to an associate array in PHP using a loop
  • Adding part of HTML to file using PHP

More answer with same ag

  • How to transfer code from and create .html file into a .php file
  • Retrieve specific link values form tag using php simple_html_dom.php
  • Handling URLs with a REST API?
  • Showing users a message while a web page is loading
  • How to print out the unique values of a PHP array?
  • How to block spam mails in inbox using php
  • Reload crontab from php , is it possible?
  • mysqli_fetch_array stop / multiple usage
  • Custom dropdown attribute on registration form
  • Echo problem when a different user logs in
  • how to group page_fan_city values by country on insights table
  • PHP forks & Shell_exec
  • PHP Math with an array
  • php: dynamic link appends content to existing page rather than opening new one
  • Get src and content from a variable
  • There is no output while creating a XML file using DOM
  • Warning: file_get_contents failed to open stream: Connection timed out in includes/simple_html_dom.php on line 75
  • Date difference based on yyyy/mm/dd AM/PM in SQL
  • Set extensions configuration in php
  • Get unique keys found in the second level of a 2d array and sum the total number of occurrences
  • script upload file doesn’t upload into uuid folder
  • Creating a beta version of site on subdomain
  • Convert a string formatted as an array TO a real array
  • Check values of sub-arrays, use key as new value in new array — PHP
  • Unable to show events from MySQL in fullcalendar in Javascript using PHP JSON
  • Detect facebook bot
  • SQL PHP ARRAY echo single array
  • Cookie recognized for example.com but not to www.example.com
  • create dynamic URLs
  • How do I have to configre XAMPP so that it executds in html documents?
  • Server issues with Plesk locking up & being non-usable
  • value not getting posted from the element generated by ajax class
  • phonegap posting data doesn’t work on android device
  • Displaying error and success messages using PHP?
  • Passing dynamic information between AJAX generated modals
  • How can I get my PHP script to load after jQuery UI tabs?
  • Recursively remove element by value
  • Issue with undefined offset with dynamically generated variables
  • Strange Curl behaviour while passing variable
  • How can I pull out Variables from XML «Like» string of text and numbers using PHP?
  • PHP verify in db if exist duplicate
  • PHP if logic returns one result on first run and different results on all subsequent runs
  • Errors with math in MySQLi
  • Concatenation of different positions of the same variable in PHP
  • writing http post contents to file in php
  • PHP — Array not recognizing dollar amount with more than 3 figures
  • Reading a .dat file as «rb» read binary
  • Uncaught Error: Call to undefined method MongoDB\\Collection::update()
  • preg_match_all with php to get measurement values with unit
  • text area output format

Источник

Читайте также:  What is iterator method in java
Оцените статью