Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Create connection
- $url = "http://localhost/AUSSIEWEB/phildoring/00102022015/wp-content/uploads/2014/05/insurance.jpg";
- // no need to copy
- $servername = "localhost";
- $username = "root";
- $password = "";
- $conn = mysql_connect("localhost", "root", "");
- mysql_select_db("aussieweb_phildoring", $conn);
- // Check connection
- if($conn){
- echo "Server Connection Success";
- }else{
- echo "Server Connection Failed";
- }
- echo "<br>";
- // no need to copy ends
- $al = alt_text($url);
- echo $al;
- function alt_text($url){
- $imageUrlRegEx = wp_url_tokenize_sc($url);
- echo "image url regex: ".$imageUrlRegEx."<br>";
- // Finding out ID
- $id = 0;
- $q = "SELECT ID from pdwp_posts WHERE guid REGEXP '$imageUrlRegEx'";
- $r = mysql_query($q);
- if($r){
- $a = mysql_fetch_array($r);
- $id = $a[0];
- //echo "id: ".$id."<br>";
- }
- //echo $id."<br>";
- // Finding alt tag
- $alt = "It's ALT tag";
- $q = "SELECT meta_value FROM pdwp_postmeta WHERE meta_key='_wp_attachment_image_alt' AND post_id='$id'";
- $r = mysql_query($q);
- if($r){
- $a = mysql_fetch_array($r);
- //print_r($a);
- $alt = $a[0];
- }else{
- //echo "unsuccessfull";
- }
- //echo "alt tag: ".$alt."<br>";
- return $alt;
- }
- function wp_url_tokenize_sc($string){
- $c = 0;
- $collection = array();
- $break = "0";
- $toReturn = "";
- $token = strtok($string, "/");
- while ($token !== false)
- {
- $toReturn = $token;
- $collection[$c] = $toReturn;
- $c++;
- $token = strtok("/");
- }
- $token = strtok($toReturn, ".");
- while ($token !== false && $break=="0")
- {
- $toReturn = $token;
- $break = "1";
- }
- // print_r($collection);
- // echo "<br>";
- $collectionSize = sizeof($collection);
- $collectionSizeStarts = $collectionSize-5;
- $lin = "";
- // echo "collection size: ".$collectionSize."<br>";
- for($cz=0; $cz<5; $cz++){
- if($cz==4){
- $lin = $lin.$collection[$collectionSizeStarts];
- }else{
- $lin = $lin.$collection[$collectionSizeStarts]."\\\\/";
- }
- $collectionSizeStarts++;
- }
- $lin = addBreakerBeforeDot($lin);
- // echo "lin: ".$lin."<br>";
- return $lin;
- }
- function addBreakerBeforeDot($string){
- $len = strlen($string);
- $toReturn = "";
- for($c = 0; $c < $len; $c++){
- if($string[$c] == "."){
- // echo "found<br>";
- $toReturn = $toReturn."\\\\". $string[$c];
- }else{
- // echo "not found<br>";
- $toReturn .= $string[$c];
- }
- }
- return $toReturn;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement