PHP - Function To Automatically Create Links
Looking for help writing a function that does the following:
Look for http:// or https:// in a string and replaces it with an <a href> tag. For example: Here is my link http://www.mydomain.com some further text here. Becomes: Here is my link <a href="http://www.mydomain.com">http://www.mydomain.com</a> some further text here. Similar TutorialsHi,
I have the following function, but told I need to run it automatically. How would I do this?
<script> function replaceText() { var list = document.getElementsByTagName("UL")[22]; var list2 = list.getElementsByTagName("LI")[29]; list2.getElementsByTagName("LABEL")[0].innerHTML = "Car"; } </script>Thanks! Hello, I'm trying to use php to have a user upload a file and then, have my site create a link --- I'm ALMOST there. My last hitch is in creating the link. From the code below, Code: [Select] echo "this is the current filename: ". $supplemental_file; echo '<a href=../../supplemental_files/' . $supplemental_file . '">Supplementary Download</a>'; I get: this is the current filename: Complaint.doc But, when I hover over the link, I get: http://localhost:8888/algebra_book/supplemental_files/Complaint.doc%22 Any thoughts on the extra %22 ?? Thanks so much.... Im messing around with functions and arrays but cant seem to get this to work. It basically creates a simple table with the parameters you specify. The array however doesnt go into the table properly. function asf_create_table($rows, $cols, $border=1, $padding=5, $td_border=1, $contents) { $table = "<table style=\"border: {$border}px solid; padding:{$padding}px;\">"; for ($t_rows=0; $t_rows<$rows; $t_rows++) { $table .= "<tr>"; } for ($t_cols=0; $t_cols<$cols; $t_cols++) { for ($i=0; $i<$cols; $i++) { $table .= "<td style=\"border: {$td_border}px solid;\">"; $table .= $contents[$i]; $table .= "</td>"; } } for ($t_rows=0; $t_rows<$rows; $t_rows++) { $table .= "</tr>"; } $table .= "</table>"; echo $table; } $t_contents = array("Cell 1", "Cell 2", "Cell 3", "Cell 4"); asf_create_table("4", "4", "1", "5", "1", $t_contents); instead of 4 cells each with Cell # in them i get 16 cells with the cell #. the 4 displayed 4 times. HI All, I would like create query when I add some one is look what the last number in field and add one ? example : you can see the img in attach IDT is primary key + auto increment Customer_id is number field customer _name is name how can create this login IDT Customer_ID Customer_name 112 5 bbbb 113 6 ccccc 114 7 eeeee Also I need the inster function and is look the last field in customer_ID and Increase one ( +1) Any help please/ THanks I am trying to use the php mail function and want to include links to a dynamic page, so I need to know how to do this... Something like: Code: [Select] $id=$_POST['id']; $mailto="email@address.com"; $mailsub="Subject"; $mailhead="From: other@address.com"; $mailbody="Your comment has been posted. You may view it by <a href='domain.com/page.php?id=".$id."'>clicking here</a>."; mail($mailto, $mailsub, $mailbody, $mailhead); I know this is not correct but I'm trying to figure out the actual way to do this... I'm trying to crawl for links in a specific website and show them at the end. The problem i'm facing is that it only show the links from the specific page not the whole pages in the website. I tried several loops with no success please give some advise. Here is the code: <?php if (isset($_POST['Submit'])) { function getLinks($link) { /*** return array ***/ $ret = array(); /*** a new dom object ***/ $dom = new domDocument; /*** get the HTML (suppress errors) ***/ @$dom->loadHTML(file_get_contents($link)); /*** remove silly white space ***/ $dom->preserveWhiteSpace = false; /*** get the links from the HTML ***/ $links = $dom->getElementsByTagName('a'); /*** loop over the links ***/ foreach ($links as $tag) { $ret[$tag->getAttribute('href')] = $tag->childNodes->item(0)->nodeValue; } return $ret; } /*** a link to search ***/ $link = $_POST['address']; /*** get the links ***/ $urls = getLinks($link); /*** check for results ***/ if(sizeof($urls) > 0) { foreach($urls as $key=>$value) { if (preg_match('/^(http|https):\/\/([a-z0-9-]\.+)*/i',$key)) { echo '<span style="color:RED;">' . $key .' - external</span><br >'; } else { echo '<span style="color:BLUE;">' . $link . $key . ' - internal</span><br >'; } } } else { echo "No links found at $link"; } } ?> <br /><br /> <form action="" method="post" enctype="multipart/form-data" name="link"> <input name="address" type="text" value="" /> <input name="Submit" type="Submit" /> </form> Say I have a chunk of code that looks like this (contains imagesx): Code: [Select] <span style="color: #0000BB">$width </span><span style="color: #007700">= </span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$img</span><span style="color: #007700">); <br /> within the code I would like to make all the php functions link to php.net I thought that the following code would work, but it does not, well because there is no spaces around the above word public function phpLinks($string){ $words = explode(" ", $string); $str = array(); foreach($words as $word){ if(function_exists($word)){ $str[] = preg_replace("/$word/i", '<a href="//php.net/'.strtolower($word).'">'.$word.'</a>', $word); }else{ $str[] = $word; } } return implode(" ", $str); } I now can not think of a good way to do this, so I am asking does anyone have any suggestions? Here is function that backup mysql database. It's working fine, but I want to download file instead of creating it. /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = '*') { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //get all of the tables if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //cycle through foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = str_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file $date= date("d-M-Y_h-i"); $handle = fopen('Backup-'.$date.'.sql','w+'); fwrite($handle,$return); fclose($handle); } Usage: Quote backup_tables('HOST','USER','PASS','TABLE'); But this will create backup file on server. I also tried to add following code in function (at the end): echo $return; header('Content-type: text/plain'); header("Content-Disposition: attachment; filename=\"$filename\""); How to just download file, without showing it on screen instead of using fwrite/fclose function? <html> <?php $id = $_GET['id']; $dbusername="web148-matt"; $dbpassword="matt"; $dbdatabase="web148-matt"; mysql_connect(localhost,$dbusername,$dbpassword); @mysql_select_db($dbdatabase) or die( "Unable to select database"); mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$id'"); $sql = mysql_query("SELECT link FROM count WHERE id='$id'"); $fetch = mysql_fetch_row($sql); $result = mysql_query("SELECT * FROM count"); while($row = mysql_fetch_array($result)) { echo "<a href=" .$row['link']. ">Link</a>"; } ?> <a href='http://www.google.com'>Google</a> <a href='/index.php?id=2'>link2</a> </html> Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> Hi, I was wondering if it is possible to have the foreign keys (FK) to automatically assign its value to the corresponding PK (primary key) it references? Let's say I have four tables (with their PK,FK and other fields) Code: [Select] TABLE document: TABLE pathway: TABLE leaf TABLE value: PK: docID PK:pathID PK:leafID PK:valueID filePath pathway FK:pathID FK:leafID fileName FK:docID value target source So when I upload a document, it is added to TABLE document, where PK docID set, and at same time I would add the filepath to TABLE pathway, and now I want TABLE leaf's FK to AUTOMATICALLY add the pathID, docID and ALSO at same time TABLE value's FK of leafID will also be added for that ONE entry that was initally added to TABLE document, pathway. Please I hope someone understand what I want to do, I know FK is for ensuring integrity of data. Please any help is appreciated. Please use my example to help me, thanks. PS: I know the formatting is off which I noticed when I went to preview the post, sorry. Hello friends, In this topic i am getting confuse, and never know how to do work. My problem is that: 1>> I want to send SMS, by PHP pages to mobile. 2>> If user write some Quotation into the calender date, then automatically SMS send to all of those friend with the quatation metter. 3>> All work is store also in MYSQL database also. So please tell me what I do in this case because over the internet only SMS sending code is available, but automatically sms sending option is not given. Please help me then i do this job easily. Thanks Hi Guys, I have the following $pattern = '<tr class="newsitem">'; when I echo this out it produces <tr class="newsitem"> </tr> Why is it automatically closing the tag? I dont want this becuase i'm using preg_replace and the tag is closed elsewhere already on the page. Hello, I am new here but I hope you can help me with a problem that I've been stuck with for days. I am trying to populate the content of a website through XML files (zipped) that are located on an FTP server. I managed to get the zip file but I'm not sure if it is the correct way: Code: [Select] function ftp_copy($file) { $conn_id = ftp_connect($ftp_host) or die ("Can't connect"); $ftp_login= ftp_login($conn_id, $ftp_user, $ftp_pass) or die ("Can't login"); ftp_pasv($conn_id, true); ftp_chdir($conn_id, "/zip_files/"); return ftp_get($conn_id, $file, $file, FTP_BINARY); } ftp_copy('1001.zip'); After that I will need to extract the zip file. I'm planning to use pclzip library for it and save the contents on a database. Also this has to happen everyday so I'm thinking about using a cron job, although hourly is also preferable since the XML files could be generated more than once per day. Am I doing it the right way or is there a better solution for this? Any help will me much appreciated! Thanks a lot! Hi all, Recently I have found myself repeating a very monotonous task on amazon's kindle direct publishing website and (being the kinda guy I am), I figured I could probably automate it without too much trouble. I'm a publisher who needs to maintain my library of lots of books and ensure that any offers are kept up-to-date. I have made screen scrapes before without too much problem, but filling in forms is a little bit more difficult. There are no CAPCHA images to enter and this is specific to my own login so I don't think I can be considered "evil", so all I want to know is how to automate my own login, click a specific link and fill in forms. Ideally I want it as easy as recording a macro, or maybe just a list of instructions. If I told a human to do it, I'd just say "go to this page and click on that, enter these details to login, then click that" and I wondered if there is something out there in cyber world that allows me to do the same? Thanks, Neil I am very new to PHP and programming in general. About 3 weeks into this. I have this simple expression and some echo in my code. $x1 = $lat_b + $lat_a1; echo "<br>lat b: ".$lat_b; echo "<br>lat a1: ".$lat_a1; echo "<br>x1: ".$x1; $lat_b and $lat_a1 are derived from some xml extractions from a yahoo geocode api (that part works fine). The results of the expression and echos above are as follows: lat b: 40.402866 lat a1: 40.252590 x1: 80 Why is $x1 rounding automatically on me? Later, I substituted the expression above with $x1 = 40.402866 + 40.252590 ; The new result (shown below) makes sense to me. lat b: 40.402866 lat a1: 40.252590 x1: 80.655456 hello guys. i need to run a script automatically at scheduled date and time. i am sending bulk emails . i need to setup an email campaign, in such a way that i can schedule like daily, monthly or quarterly.. can u guys give few tips to get it done.. Hi, I've been wondering if it is possible to load a php page according to certain time. For example at 12:00 pm a php form will pop up automatically informing an employee to fill in something in the form, another form will pop up at 4:00 pm, etc... Thanks in advance This is an example of the forwarding section of the pagination code: if (($filename == $profile) && isset($select_category)) { echo " <a href='{$filename}?user=$user_name_get&sort_category=$select_category&sortSubmit=submit¤t_page=$next_page'>></a> "; echo " <a href='{$filename}?user=$user_name_get&sort_category=$select_category&sortSubmit=submitcurrent_page=$total_pages'>>></a> "; } elseif ($filename == $profile) { echo " <a href='{$filename}?user=$user_name_get¤t_page=$next_page'>></a> "; echo " <a href='{$filename}?user=$user_name_get¤t_page=$total_pages'>>></a> "; } elseif (($filename == $index) && isset($select_category)) { echo " <a href='{$filename}?sort_category=$select_category&sortSubmit=submit¤t_page=$next_page'>></a> "; echo " <a href='{$filename}?sort_category=$select_category&sortSubmit=submit¤t_page=$total_pages'>>></a> "; } else { echo " <a href='{$filename}?current_page=$next_page'>></a> "; echo " <a href='{$filename}?current_page=$total_pages'>>></a> "; } $filename = the opened filename + extension $profile = profile.php $index = 01.php I'm using several if and elseif statements to not have the pagination clash with the other GET data. I'd like to have the pagination simply append at the end of the URL with an ampersand if there is GET data already. If there's no GET data at all I'd like to have it append with a question mark. The problem with the solution I have now is, if I use more GET data in the future I'll have to use more elseif statements it will get out of hand. I've noticed that if you send GET data over a form that has method on GET, then the GET data will automatically decide if to add a question mark or an ampersand. In that sense my question would be, is there a way to make the pagination decide automatically to use a question mark or an ampersand? I'm wanting to make a sitemap for my website but as it's quite big there are a lot of url's I need to include. I was wondering if anyone know's of a way this can be done using PHP. e.g. using PHP to generate a list of URL's. I had a think myself but wasn't sure how to do it. Thanks for any help. |