PHP - Help... Checking If Dom Textcontent Matches Row Thats In Database.
Hello,
I am trying to get this backlink checker that checks to make sure another website has my link on their website, so far I can check to make sure the "href" link is there and is correct, but I cant get the textContent to prove valid or not it seems to always be proving true even when the textConent is not in the mysql database. The other persons website will have this: <a href="http://businessinvestingsorce.com">Business Investing Source</a> I need to make sure Business Investing Source (the textContent) matches the anchor in the database. Here is my code: Code: [Select] <?php function CheckForAnchorMatch($anchortext) { $query = mysql_query("SELECT * FROM allowed_anchor WHERE anchor='$anchortext'"); if(mysql_num_rows($query) != 0) { return true; } return false; } function CheckForTargetUrl($links, $target) { foreach ($links as $link) { if (strpos($link, $target) !== false) { return true; } } return false; } function ExtractHrefLinks($html) { $dom = new DOMDocument; $linkUrls = array(); @$dom->loadHTML($html); $links = $dom->getElementsByTagName('a'); foreach ($links as $link){ $linkUrls[] = $link->getAttribute('href'); } return $linkUrls; } function ExtractAnchorText($html) { $dom = new DOMDocument; $AnchorTexts = array(); @$dom->loadHTML($html); $links = $dom->getElementsByTagName('a'); foreach ($links as $link){ $AnchorTexts[] = $link->textContent; } return $AnchorTexts; } function backlink_check($contenturl){ $url = 'businessinvestingsource.com'; $source = $contenturl; $falseFound = false; $html = file_get_contents ( $source ); $links = ExtractHrefLinks($html); if (CheckForTargetUrl($links, $url) === false) { $falseFound = "true"; $reportArray[$source] = 0; } else { $falseFound = "false"; } $html = file_get_contents ( $source ); $anchortext = ExtractAnchorText($html); if (CheckForAnchorMatch($anchortext) === false) { $falseFound = true; } else { $falseFound = false; } return $falseFound; } ?> Help greatly appreciated Similar TutorialsHi guys and girls, I am having trouble finding out wether the query made no matches rather than just displaying the matches. So what I would want is for the search term to look at the database, and if there's not matches then say, "No match for your search term" Code: [Select] function search_applications() { global $dbc; echo '<form method="post" action="" id="search">'. "\n"; echo '<label for="search_applications">Search for an application</label>'. "\n"; echo '<input type="text" name="search_applications" />'. "\n"; echo '<input type="submit" name="submit" />'. "\n"; echo '</form>'. "\n"; if(isset($_POST['submit'])){ $search_applications = $_POST['search_applications']; if ($search_applications == "") { echo "<p>You forgot to enter a search term"; } //if (preg_match("/\b$search_applications\b/i")){ if(preg_match("/^[ a-zA-Z]+/", $search_applications)){ //for testing the variables //echo $search_applications; $sql="SELECT title, category, content FROM distributors_content WHERE title LIKE '%" . $search_applications . "%' OR category LIKE '%" . $search_applications ."%' OR content LIKE '%" . $search_applications ."%'"; $result=mysqli_query($dbc, $sql); //-create while loop and loop through result set while($row=mysqli_fetch_array($result)){ $title =$row['title']; $category=$row['category']; $content=$row['content']; //-display the result of the array echo "<ul>\n"; echo '<li> <a href="index.php?article='.$row['title'].'&&page=application" title=""> '.$title . ' ' . $category . '</a></li>'."\n"; echo "</ul>"; } }else{ echo "<p>Enter another search term</p>"; } } } Any pointers would be good Thank you Hello, I am trying to get this backlink checker to work i have it working so it checks that the link itself matches and is there but this is the harder part that I don't understand. I want to have it also check the nodeValue to make sure that it matches one of the nodeValue's from a mysql table this is the code I have to make it check the href link Code: [Select] function CheckForTargetUrl($links, $target) { foreach ($links as $link) { if (strpos($link, $target) !== false) { return true; } } return false; } function ExtractHrefLinks($html) { $dom = new DOMDocument; $linkUrls = array(); @$dom->loadHTML($html); $links = $dom->getElementsByTagName('a'); foreach ($links as $link){ $linkUrls[] = $link->getAttribute('href'); } return $linkUrls; } function backlink_check($contenturl){ $url = 'businessinvestingsource.com'; $source = $contenturl; $falseFound = false; $html = file_get_contents ( $source ); $links = ExtractHrefLinks($html); if (CheckForTargetUrl($links, $url) === false) { $falseFound = "true"; $reportArray[$source] = 0; } else { $falseFound = "false"; } return $falseFound; } Now this all works fine, I just need it to check the actual nodeValue (anchor text as well) meaning check this: <a href="http://google.com">Google</a> There is a mysql table called "allowed_anchors" with 2 rows "id" and "anchor" I need it to check if the nodeValue matches 1 of the allowed_anchors from the table. If anyone knows how I can do this that would be very great i have been trying to figure it out for hours with no luck. Thanks very much for any help to come. php5.2, mysql server5.02: if record exists,append random digit to end of information in rows column then add to database If user mike already exists and another mike is trying to create a user id I would like to keep the old mike record like it is, then add a new mike record, but add a unique digit to the end of the name mike before the record gets added to the database as a new row. Thank you kindly! The Script:
pdo_connect.php:
<?php $dsn = "mysql:host=localhost;dbname=2354"; $db = new PDO($dsn, "root", ""); ?>pdo_test.php: <?php try{ require_once("pdo_connect.php"); }catch(Exception $e){ $error = $e->getMessage(); } ?> <!DOCTYPE html> <html> <head> <title>Database Connection with PDO</title> </head> <body> <h1>Connection with PDO</h1> <?php if($db){ echo "<p>Connection successful.</p>"; }elseif(isset($error)){ echo "<p>$error</p>"; } ?> </body> </html>I have just watched a tutorial and tried out this script. The issue is that I am getting the following notice alongside with the error message: Notice: Undefined variable: db in C:\xampp\htdocs\oophp\pdo_test.php on line 18 SQLSTATE[HY000] [1049] Unknown database '2354'By the way this notice does happen in the tutorial as well. My question is: How to have this in ways, where the notice does not occur? Hello! I need to loop through a list of numbers and check if they are present in a column in a database or not. I'm having a hard time figuring out how to check the column value by value and compare to a incrementing $i value. here is my query... Code: [Select] $query2 = mysql_query("SELECT * FROM video"); $column = mysql_fetch_array($query2); echo $column2['cable_number']; this only echoes me the first ['cable_number'] in the database. i need to get every single one, and perform actions on each one as they come through. and here is my for() statement Code: [Select] for($i=100;$i<=$highest;$i++){ check if $i is in the database. if it is(do something) if it isn't(do something) } i need to use that $i each iteration and see if it's present in the 'cable_number' column in the database. then i do something and continue on with the next i$ value. Hey I'm trying to check a row in my database to see if its empty but this isnt working $usercheck = mysql_query("SELECT pet FROM users where name='$user'"); $returned_rows = mysql_num_rows($usercheck); if ($returned_rows == 0){ // do stuff if no pet }else{ echo 'There was ' . $returned_rows . ' records found.'; } The problem is its not checking the row pet its just checking to see if anything exists my database has id name pet 1 joe <empty> its just seeing joe and echoing "there was 1 record found" instead of seeing that the row pet is empty. thanks for the help Ok guys, I am working on my code as I am checking the row in a database that if i have got a same row that I insert the functions in the URL then throw the error that says "you can't store". When I am checking as the rows have already exist, i keep getting "you can now store". Do you know how i can check in a database to see if the rows is exist? here's the code: Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $image = clean($_GET['image']); $strings = clean($_GET['strings']); $username = clean($_GET['user']); $password = clean($_GET['pass']); if (isset($_GET['user']) && (isset($_GET['pass']))) { if($username == '' || $password == '') { $errmsg_arr[] = 'username or password are missing'; $errflag = true; } } if (isset($_GET['image']) || (isset($_GET['strings'])) || (isset($_GET['user']))) { if($image == '' || $strings == '' || $username == '') { $errmsg_arr[] = 'image, strings or username are missing'; $errflag = true; } } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['image'])) { $insert[] = 'image = \'' . clean($_GET['image']) . '\''; } if(isset($_GET['user'])) { $insert[] = 'user = \'' . clean($_GET['user']) .'\''; } if(isset($_GET['pass'])) { $insert[] = 'pass = \'' . clean($_GET['pass']) . '\''; if (count($insert)>0) { $names = implode(',',$insert); if($image && $strings && $from && $username) { $qry="SELECT * FROM members WHERE username='$username'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); $row=mysql_fetch_assoc($result); if ($row >= 1) { echo 'you cant store.'; } else { echo 'you can now store'; } } elseif($username && $pass) { echo "working 2"; } } } ?> Probably a silly question, but say you have a value in a mysql database that (naturally) can be either be blank or have characters in it. If in my PHP I am doing a check to see if that returned field from the database HAS or DOES NOT HAVE a value entered in it, what is the proper way to do it? For example, you could do either of the following below (and I'm sure there are probably 10 other ways to do it as well). Is one of these quicker/more efficient than the other? I know it probably does not matter in the grand scheme of things because it's such a quick check either way, but if one way is more "proper" than the other, please let me know... Code: [Select] if ($mysqlvalue!=="") OR if (strlen($mysqlvalue>0)) OR Is there an alert method for the MySQL database or something similar?
What is the proper way to check if the MySQL database connection is working?
I mean other than "creating" and "retrieving" with "insert" and "select".
Hello guys. I have the following code and I would like to count the number of times that the word has been replaced. I tried echo count ($replacement) and echo count ($match) but both only show "1". I want to be able to tell if there has been a replacement and send a warning email and/or add a flag in the db. Code: [Select] $search_for_bad_words = mysql_query("SELECT * FROM badwords WHERE 1"); $ad_title2 = $ad_title; $ad_body2 = $ad_body; //$wordlist = "shit:cr*p|dang:d*ng|shoot:sh**t"; $seperate_text = "|"; $entry_seperate_text = ":"; while($row = mysql_fetch_array($search_for_bad_words)) { $wordlist = $wordlist.$seperate_text.$row[word].$entry_seperate_text.$row[r_word]; } $words = explode('|', $wordlist); foreach ($words as $word) { list($match, $replacement) = explode(':', $word); $ad_title2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_title2); $ad_body2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_body2); } Thanks for all your help! I'm trying to come up with some code...and need to echo certain things based on which query failed. There are several query's and while loops nested together. I'm trying to use this... Code: [Select] <?php $rs = mysql_query($sql,$dbc); if (! $rs) { echo "You aren't scheduled to work in the next seven days...but check back often as the schedule is adjusted often."; } $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; //rest of code here...which work when there are matches... ?> With no matches, it isn't echoing anything...instead of "You aren't scheduled to work in the next seven days...but check back often as the schedule is adjusted often." If I echo out $rs, I get RESOURCE ID #6 Any ideas? Thanks! Im trying to insert a name into my database but I need it to go into the column that matches the sessions user id Code: [Select] "INSERT INTO users SET name = '".$_POST['name']."'"; how do I tell it to put name into name column with id matching Session id. really appreicate if someone could please help me with this. I have this query to show the current class I'm in: Code: [Select] $GetTimeTable = "SELECT * FROM timetable WHERE username='$username' AND Subject_date='$today_date'"; Then I have this to display current class: Code: [Select] if($TimeNow >= $Start_time && $TimeNow <= $End_time){ echo "Current Class: "; echo $Subject;} How would I find next class that day? Hi there I am beginning to learn regex in php. I was wondering why the following regex pattern wasn't finding the two words in the string and replacing them with welcome? '/(Hello).*?(Hi)/is' Code: [Select] $patterns = array(); $patterns[0] = '/(Hello).*?(Hi)/is'; $replacements = array(); $replacements[0] = 'Welcome'; ksort($patterns); ksort($replacements); echo preg_replace($patterns, $replacements, $string); Any help would be much appreciated. Thanks a million! First time post, be easy on me...
I'm using preg_match_all to return an array with all the matches. I know I'm missing something fundamental, but I either keep looking past it or am more screwy than I know.
Sample String
CC-BY-ND-NCI'm using the following code preg_match_all("/cc|creative commons|copyright|by|sa|nc|nd/i",$exifmeta['copyright'],$cmeta)I would expect to see Array ( [0] => Array ( [0] => CC [1] => BY [2] => ND [3] => NC ) )What I get is Array ( [0] => Array ( [0] => CC [1] => BY [2] => ND [3] => NC [4] => sa ) ) Hi, I am doing an EDIT user page and would like to check records with a dropdown and then set as selected, please help! <select name="BrokerID" class="small-input"> <option value="Please select an option">Please select a Broker</option> <?php while($row2 = mysql_fetch_array($broker)) { echo '<option name="BrokerID" value="'.$row2['BrokerID'].'">'.$row2['BrokerName'].'</option>'; } ?> </select> Hi
I want to echo out something when I post the value of a radio button and this value matches the same name of a html file. How can I formulate my code to achieve that?
What I have so far:
<?php if (isset($_POST['submitradio'])) { $selected_dir = $_POST['radio1']; echo substr($selected_dir, 0, -4); echo '<img src="'.$selected_dir.'" />'; } ?>So far I get for example the name of the image(order.gif) and the image order. gif. What I now want is to formulate my code so that I can say if I have an image called "order.gif" and a file called "order.html" that I can then echo out some thing. I don't want to actually name the image or the html file. I just want to say if I have two different file types that start with the same name then I can echo out what ever. How can I do that? I have a website http://www.pbm-biz.com/cricket/ where I am streaming Live Cricket world cup matches. My question is that during the streaming, I would like to keep the code in PHP so that others don't copy it. I can't find any solution. Any suggestions. Thanks, Faisal Folks, I have a dropdown, once values are selcted, these values should be put in a URL structure so that it matches with the one MoD_rewrite rule in my .htaccess. Here is my Mod_Rewrite Rule: RewriteRule ^(.*)/([^/]*)\.html$ search.php?q=$1&sc=$2 [QSA,L] Here is my Dropdown Code: <div id="search" > <form id="searchform" method="get" action="search.php"> <label>Search By Brand/ Manufacturer: </label> <select name="q"> <option value="SelectBrand">Select Brand</option> <?php if(isset($this->search->options)): ?> <?php foreach($mfg as $lolachild): ?> <option value="<?php echo $lolachild; ?>"><?php echo ucwords($lolachild); ?></option> <?php endforeach; ?> <?php endif; ?> </select> <select name="sc"> <option value="All"><?php eprint(LangAll); ?></option> <?php if(isset($this->search->options)): ?> <?php foreach($this->search->options as $cat): ?> <option value="<?php echo $cat->value; ?>"><?php echo $cat->name; ?></option> <?php endforeach; ?> <?php endif; ?> </select> <input type="submit" value="<?php eprint(LangSearch); ?>" /> </form> </div> Problem is, upon Submit, it goes to this link structu http://mydomain.co.uk/search.php?q=fisher&sc=302 It should rather be: http://au2.co.uk/fisher/302.html What am i missing or doing wrong? Cheer Natasha |