PHP - Embedded Image Tag In String
i want to be able to extract a string from a variable when an IMG tag is present and then use the link of the image to create an image tag of it's own to be displayed
let's say i have a string $post which contains the following... (ignoring the quotations) here is some random text ["IMG"]http://www.somedomain.com/someimage.jpg[/"IMG"] here is some more random text how would i be able to extract the string inside the [IMG] tags and replace it with a different string in the same position excluding the [IMG] tags such as <img src=''http://www.somedomain.com/someimage.jpg"/> any recommendations on how i would be able to do this? Similar TutorialsI want to place Custom background image for embedded media player Can anyone help me? hello again need some advice cant get it working Code: [Select] SELECT * FROM `tsue_members` WHERE memberid=0 if ($row['memberid'] == '0') { $img = "1.gif"; } echo $img; Hi.. I am relatively new. I am trying to show an image link in my code below: $image = "<img src=<imgpg/" . $part_no . ".JPG />"; <td class = "guide_body" width = "66%"></td><td align = "center"><?php echo $image;?> There is more code but these are the problem lines I believe. Both are within the php environment.
This is producing:
It is supposed to look like this: So it is adding %3C for some reason between localhost and imgpg directory. I have no idea why this is happening. Is there something I can do to prevent this from happening? Or is there something I can do to erase the extra characters. (I'm not sure if they might be different though at some point. I have the same problem both on my local computer and the remote server.) Thanks very much for any help!! Hi group, I need to create a string to be used by base64_encode to build an SVG file. The source for the string is an image I built in memory. Code: [Select] $img = imagecreatetruecolor( 50,50 ); Other stuff, draw circles, test, ect. I currently write it out to disk with: Code: [Select] imagepng( $img, "$Name.png" ); Then read it back in and process it to create an SVG file. I would like to avoid writing it to disk, so how can I create a string for base64_encode from an in memory image?? Thanks for your time. Hello, I am attempting to create a script where a user puts a text string into a form and clicking on submit. Then it adds that text string to a mysql database and gives the user a link back to it. Something like mysite.com/key.php?id=4 and when going to that link it will display the text string from the database but printed in an image. I wrote something up but I cannot get it to work. I may be a little in over my head. Any help is appreciated.
The way I coded this all to work is the user inputs the information into index.php which givekey.php inserts that into the database. I have not yet figure out how to do this in one single step. After that I wanted it to navigate directly to key.php which would display the key and the link to that page with the ?key=XX attribute. getkey.php <?php require_once 'dbinfo.php'; // database connection $id = $_GET['id']; // do some validation here to ensure id is safe $link = mysql_connect($servername, $username, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($database) or die( "Unable to select database"); $sql = "SELECT ukey FROM keycode WHERE id=$id"; $result = mysql_query("$sql"); $row = mysql_fetch_assoc($result); mysql_close($link); header("Content-type: image/png"); echo $row['ukey']; ?> key.php <html> <head> <title>Your Key Is Ready</title> </head> <body> <img src="getkey.php?id=1" width="175" height="200" /> </body> </html>index.php <html> <head> <title></title> </head> <body> <section id="mid_section"> <div id="boxes"> <h1> Testing input key </h1> <br/> <form id="myform" action="givekey.php" method="post"> Key:<br /> <input type="text" value="ukey"> Source:<br /> <input type="radio" value="hb">HB<br /> <input type="radio" value="ig">IG<br /> <input type="radio" value="other">Other<br /> <button id="sub">Submit</button> </form> </body> </html>givekey.php <?php include_once('dbinfo.php'); $conn = mysql_connect($servername, $username, $password); $db= mysql_select_db($database); $ukey =$_POST['ukey']; $hb =$_POST['hb']; $ig =$_POST['ig']; $other =$_POST['other']; if(mysql_query("INSERT INTO `keycode`(`ukey`) VALUES ([$ukey]); INSERT INTO `source`(`hb`,`ig`,`other`) VALUES ([$hb],[$ig],[$other]);")) ?> Edited by chrisb302, 13 November 2014 - 12:18 AM. Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick Ok, this is killing me, So I'm finally asking for help. I'm working on a website, which streams videofiles from external links. The site plays & allows you to download the videos from the same external link. I need to mask the url of these videos. At the moment, I have successfully masked the url when downloading. If you click the download image, rather than the path being http://externalsite.com/videofile.avi its http://mysitename.com/external.php?id=xx&mid=xx So that is nicely hidden. However, I am having a problem when it comes to the embedded player on the page. At the moment i am using flowplayer for flv & mp4 videos, and just the usual embed for avi videos. Flow players embed code is like this --------------------------------------------------- <a href="<?=$videoFile?>" style="display:block;width:740px;height:400px;" id="player"> </a> <script language="JavaScript"> flowplayer("player", "<?=url::base()?>flowplayer-3.2.5.swf", { clip: { autoPlay: false, autoBuffering: true } }); </script> ----------------------------------------- At the moment, the player only works if i put the url in this format: http://externalsite.com/videofile.avi and wont work in this format http://mysitename.com/external.php?id=xx&mid=xx all download.php does is check the file exists, sets the headers and prompts users to open or save. Why isnt this working with the player? Please see the attached external.php file for my heade info etc to hopefully shed some light on this Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } I found the following forum topic and have implemented the solution provided at the bottom: http://www.phpfreaks.com/forums/index.php?topic=310258.0 Code: [Select] <?php $cnx = fopen("data/Book1.csv", "r"); //open example.csv echo("<table>\n\t<tbody>\n"); // echo the table while (!feof ($cnx)) { // while not end of file $buffer = fgets($cnx); // get contents of file (name) as variable $values = explode(",", $buffer); //explode "," between the values within the contents echo "\t\t<tr>\n"; for ( $j = 0; $j < count($values); $j++ ) { // echo("\t\t\t<td>$values[$j]</td>\n"); } echo"\t\t</tr>\n"; }; echo("\t</tbody>\n</table>"); fclose($cnx); //close filename variable ?> It works great. One question though - - what might it take to add an if/else statement that inserted the following for the first row in the CSV file ... Code: [Select] echo("\t\t\t<th>$values[$j]</th>\n"); ... and inserted the following for every row after the first ... Code: [Select] echo("\t\t\t<td>$values[$j]</td>\n"); This way I can better control my table through CSS. Any ideas? I'm creating a learning tool where people can paste in information and learn about random subjects.
Ideally for a desktop view eg. widescreen, a browser/search engine is on the left, and the interface is on the right.
So I need to embed a browser, I have tried to embed Google but I think, obviously, that they do not permit that.
I have seen possible alternatives like Chromium or Mozilla not firefox, something else "Gecko?"
Anyway, aside from not knowing what a browser is... for example how else can you access a website without a browser, SSH right? But it's about parsing / interpreting the languages correctly...
So what options do I have? Or should I just optimize the website to be used split screen with a browser in a separate tab? (Currently what I'm doing).
I have a large mysql table with over 2600 rows but only something like 350 unique names. what I'm trying to do is make a HTML table row and select element for every unique name. When the loop encounters a duplicate name, I want it to create new options for all of the duplicate rows. Here is a snippit of my table: Name D01_03 EMS Agency State 10002 Appropriate 2 digit FIPS code D01_04 EMS Agency County 10003 Appropriate 5 digit FIPS code D01_05 Primary Type of Service 5610 911 Response (Scene) with Transport Capability D01_05 Primary Type of Service 5620 911 Response (Scene) without Transport Capability D01_05 Primary Type of Service 5630 Air Medical So names D01_03 & D01_04, should have their own table rows and select elements and D01_05 should just be one row and one select element with all of the entries in their own option tag. The code (partially): $result = mysql_query("SELECT * FROM tblvalues") or die(mysql_error()); //Return the table row by row while($row = mysql_fetch_array($result)) { //Count occurances of element $multi = mysql_query("SELECT count(fldelement) FROM tblvalues WHERE fldelement = \"$row[fldelement]\"") or die(mysql_error()); $multicount = mysql_result($multi, "0"); $icount = $multicount - 1; if ($multicount > 1){ while($row = mysql_fetch_array($result) && $icount >= 0){ //Stuff to do for rows with duplicate names } } else { //Stuff to do for unique rows. } } So, what happens is the outer loop goes until it hits the inner loop, then the inner loop finishes off the remaining rows. i've tried adding a counter to decrement by 1 every iteration of the inner loop, and have it kick out when it hits 0, but that didn't work. Basically, what i think i'm trying to ask is, how do I make the outer loop skip over the lines that the inner loop covered OR how do I make the inner loop kick back out to the out loop when it is done with the duplicates? I'm really sorry for that long, confusing post, but I have been going crazy over this all day, any help would be more than appreciated! I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this! hey guys im trying to find a string inside a string which could be made up of different things eg... {$test}, {$test1}, {$test2} etc (but the varable inside could be called anything hence maybe using regex im not sure?) is this possible?...i hope you guys understand....thanks PHP = 5.5.14
MySQL = 5.2.17
This simple .php script works as a standalone OK:
<?php require '<snip partial URL>mysqli.php'; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT `callsign`, `qth`, `submitted` FROM `lqplogs` ORDER BY `callsign`"); echo "<table> <tr> <th><u>CALLSIGN</u></th><th><u>QTH</u></th><th><u>LOG SUBMITTED</u></th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['callsign'] . "</td>"; echo "<td>" . $row['qth'] . "</td>"; echo "<td>" . $row['submitted'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?>A separate .html page with other info works by itself OK too, but when I try to embed the PHP script (with PHP start & end tags, of course) *between* these HTML tags: <table> <tr> <td> ... Full PHP Script Embedded here... </td> </tr> </table> I get this mess: "; while($row = mysqli_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo " CALLSIGN QTH LOG SUBMITTED " . $row['callsign'] . " " . $row['qth'] . " " . $row['submitted'] . " "; mysqli_close($con); ?>Any thoughts as to why are appreciated. Thanks! - FreakingOUT Hi All, There is a very interesting solved topic here (http://www.phpfreaks.com/forums/index.php?topic=304966.0) about how to access elements in embedded _POST array. But before accessing an element, it might be appropriate to check whether the array it is supposed to be in exists. According to the solution given in the topic indicated above, Code: [Select] $_POST['matType'] is an example of embedded array . Is there a way to check if this array exists? Thanks in advance for your help. Hi folks, I'm using this code to display a picture that is uploaded in a form. Code: [Select] print "<img src='http://www.coast2kosci.com/mylongrun/test/photo_uploads/$imgx' width='300' height='300' alt='Your photo' />"; At first I tried specifying only the width, without the height. But for tall photos, the display wasn't really what I was after. Then I specified both width and height, which results in a mis-scaled photo. Is there any way that I can specify the height and width atributes as a sort of maximum / or limiter. Ie: If the height is greater than the width, limit the height to 300, and if the width is greater than the height, limit the width to 300? Thanks for your time, Dave I have a video system on my website that allows users to post videos and it embeds youtube videos into the site, I would like to create an interface where you can comment on the actual video itself and it go to youtube's commenting stream. Is that possible? difficult? |