Sample Application

Using HTML Image Tag Inside PHP

Using HTML Image Tag Inside PHP

  1. Use the Image Tag Inside a PHP Variable
  2. Store Image URL Source in PHP
  3. Convert URL Strings With str_replace() and Using iframe Tag in PHP

Using HTML tags inside PHP ensures the proper use of quotations. You only need to store your markup inside a PHP variable.

The HTML must remain within the quotations of the PHP strings whenever we substitute the PHP variable with the HTML tags. Hence, the actual quotes for your img tag will not imply.

php $demo = $demo = . 'Sample Application'; ?> 
php $demo2 = $demo2 . "\" />"; ?> 

Now let’s have examples of how to use HTML tags inside PHP.

Use the Image Tag Inside a PHP Variable

 head>  title> Use Img Tag inside PHP Script title>  style>  img   height: 400px;  width: 400px;  display: block;  margin-left: auto;  margin-right: auto  >  style>  head> body align='center'>  form action='index.php' method='post'>  input type='submit' name='image' value='Use HTML Image Tag inside PHP' />  input type='submit' name='video' value='Use HTML Video Tag inside PHP' />  input type='submit' name='method2' value='Use HTML Img Tag in PHP method 2' /> form>  body>  html> 
## Note: You do not need to reuse the HTML code above again. It contains markup for all three examples. (Also available in the code directory)  php  if(isset($_POST['image']))  $use_img_tag_php = $use_img_tag_php . '   
'; echo $use_img_tag_php; > ?>

We have used single quotes for the PHP and double for the HTML. With this method, there is no need to echo your variable inside the source of the image tag anymore.

Store Image URL Source in PHP

You only need to store your URLs in a PHP variable and echo the source inside the src attribute of the img tag.

php if(isset($_POST['method2'])) //Asign URL path to a variable  $imgurl = "demoimage.gif"; //Use image URL from your root directory //Now it dynamic //Close php tag  ?>   Sample Application
> //close php tag, the isset condition will only load HTML inside its body ?>

Convert URL Strings With str_replace() and Using iframe Tag in PHP

If you have copied any youtube URL and you want to use this in an HTML iframe . At the same time, you want it to be dynamic.

We will put HTML tag inside PHP while also using str_replace() .

php if(isset($_POST['video'])) $fetchyoutubevideo = "https://www.youtube.com/watch?v=/AkFi90lZmXA"; $embed_it = str_replace("watch?v=", "embed/", $fetchyoutubevideo); echo $embed_it; echo $use_video_tag_php = $use_video_tag_php.'  src="https://www.delftstack.com/howto/php/use-image-tag-inside-php/'%3C/span%3E%3Cspan%20style=color:#666%3E.%3C/span%3E%3Cspan%20style=color:#19177c%3E$embed_it%3C/span%3E%3Cspan%20style=color:#666%3E.%3C/span%3E%3Cspan%20style=color:#ba2121%3E'" title="Video Title" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen >  '; > ?> 
  1. First parameter — ( watch?v ) = string
  2. Second parameter — ( /embed ) = string
  3. Third parameter — ( $embed_it ) = PHP variable (URL String)

The str_replace function has replaced the first parameter with the second and stored it in the third parameter.

Sarwan Soomro is a freelance software engineer and an expert technical writer who loves writing and coding. He has 5 years of web development and 3 years of professional writing experience, and an MSs in computer science. In addition, he has numerous professional qualifications in the cloud, database, desktop, and online technologies. And has developed multi-technology programming guides for beginners and published many tech articles.

Related Article — PHP HTML

Источник

Solution 2: If i understood your question correctly, you are trying to add URL (Entered by user) to the HTMl text, on clicking submit. use header for redirecting Question: I need regular expression that converts links in plain text to HTML links. Anyhow, if you’re really tempted to use it, your regex would look like this Also, no need for second expression, as Gavriel points out, just add an Solution 2: Why do you have it twice?

My code is below. I wanna add to link my website icon to the main page but its seems like it doesn’t work.

$output .= " "; 

Because an element has no href attribute. You can’t make something a «link» just by adding an href to it.

The is the content of your «link», and the link itself is a standard element:

Php — find link to image in text and convert to link, So I need some php script that searches through the text for links and if it finds a link, checks that it links to a picture. It also needs to be able to

Learn how to use image as a link in HTML. We will use the img tag inside the anchor tag i.e
Duration: 3:14

I want to make it so i can have a html form that says «Put Image Link Here» and then when you click submit it will add it into the top of a txt file.(above other Sections of html) So Like This:

Add Your Image: Raw Image File:
Link to image Page:

This is very insecure, but if you’re just trying to learn the basics of how some of this stuff works, then I hope that this is a helpful demonstration.

You can use file_put_contents to write to files on disk. Be cognizant of operating system file permissions for the user account executing the script (web server). I use the /tmp directory for this example because it usually exists on linux operating systems with global read/write permissions.

Make sure to use the FILE_APPEND flag.

If filename does not exist, the file is created. Otherwise, the existing file is overwritten, unless the FILE_APPEND flag is set.

*/ if(isset($_GET[‘lastname’])) < $string_to_write = '

‘; // if our file doesn’t exist, then create it if (!file_exists($file)) if(!touch($file)) trigger_error(‘ERROR: could not create file on disk’, E_USER_ERROR); // Write the contents to the file, // using the FILE_APPEND flag to append the content to the end of the file // and the LOCK_EX flag to prevent anyone else writing to the file at the same time if (!file_put_contents($file, $string_to_write, FILE_APPEND | LOCK_EX)) trigger_error(‘ERROR: could not write to file on disk’, E_USER_ERROR); // redirect to wherever header(‘Location: /’); > // print the file to screen include($file); ?> Add Your Image: Raw Image File:
Link to image Page:

I’ll leave the «Image Source» part for you. Uploading files is a different question.

 /* header('Location: url'); */ /* uncomment the above line for redirect */ ?>    
Add Your Image: Link to Image page:

If i understood your question correctly, you are trying to add URL (Entered by user) to the HTMl text, on clicking submit.
use header for redirecting

How to put an image link in PHP script, You can take the image location from db with the ‘postid=20 & then echo it in the src. That will be simple. – Mithun Satheesh

I need regular expression that converts links in plain text to HTML links. my code is:

but this expression will make the image url to href as well. so my question is how to avoid if the url is in img tag like.

The text: https://yahoo.com this is my image

i want this one https://yahoo.com this is my image

Another drawback of lookbehind is that it has to be fixed length. This means you cannot grab onto img since there may be additional attributes between it and the src . Anyhow, if you’re really tempted to use it, your regex would look like this

Also, no need for second expression, as Gavriel points out, just add an s?

Why do you have it twice? The only difference I see is the s in the https, but that you could achieve like this:

IMHO you got the result because the 1st line did what you wanted for and the second line «did it once again». If your input has the link and the img url in one line then you could maybe combine the 2 regexes to 1 long one that catches both. That way the 2nd each «half» of the regex will only replace it’s «part» of the line

The correct way to path files/images/links on html, Well, like i said, after some time i found a «bug». If i put / after .php link, for example: example.com/test.php/ , all my images/js/css

Источник

Upload Image From URL Using PHP

In this tutorial we will show you how to upload an image from url using PHP. You have to enter complete url of image which ends like file.jpg or any image extension and your image will be uploaded.

You can use this method to download any kind of file and you can also create big application for file downloading.

Upload Image From URL Using PHP

To Upload Image From URL It Takes Only Three Steps:-

  1. Make a HTML file and define markup
  2. Make a PHP file to upload image from url
  3. Make a CSS file and define styling

Step 1. Make a HTML file and define markup

We make a HTML file and save it with a name upload.html

In this step we create a form to upload image from url entered by user and send it to ‘upload_image.php’ page for upload we also add css file which we were going to create in next step.

Step 2. Make a PHP file to upload image from url

We make a PHP file and save it with a name upload_image.php

In this step we get the image url and get image content using file_get_contents() function and then specify upload folder and image name in which we want to save image and then we use file_put_contents() to save image in upload folder.

Step 3. Make a CSS file and define styling

We make a CSS file and save it with a name upload_style.css

body < margin:0 auto; padding:0px; text-align:center; width:100%; font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif; background-color:#34495E; >#wrapper < margin:0 auto; padding:0px; text-align:center; width:995px; >#wrapper h1 < margin-top:50px; font-size:45px; color:#FDF2E9; >#wrapper h1 p < font-size:18px; >#text_div input[type=»text»] < width:300px; height:35px; padding:10px; >#text_div input[type=»submit»] < width:100px; height:35px; margin-top:5px; background:none; border:1px solid white; color:white; font-weight:bold; >#text_div img

That’s all, this is how to upload image from URL using PHP and HTML. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Источник

Читайте также:  Язык программирования java scripts
Оцените статью