Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Posts posted by The Little Guy

  1. don't use ajax to get main content, use it for processing little pieces of information or retrieving un-important information many robots can't handle ajax. Using to go from page to page will decrease your SEO due to the lack of information about the new page.

    I disagree. With Andy-H's method - a fallback method is given and search engines can follow those links. Thus, no decrease in SEO would happen.

     

    That was meant for if you didn't have a fallback. Sorry.

  2. don't use ajax to get main content, use it for processing little pieces of information or retrieving un-important information many robots can't handle ajax. Using to go from page to page will decrease your SEO due to the lack of information about the new page. Take this page for example: http://phpsnips.com/snip-29 it hides shows/hides information using javascript without using ajax the information is all there so the Google bot or other bot can still read information about the page but visually you don't see everything unless you switch tabs.

     

    As Andy said, make it so the site functions well if the user doesn't have javascript turned on, an example would look like so (jquery):

     

    <script>
    $(document).ready(function(){
    $("#myElement").click(function(){
    	// Do some cool stuff!
    	// returns false so we don't follow the html link
    	return false;
    });
    });
    </script>
    <!-- HTML CODE IS HERE -->
    <a href="more_info.php?id=123">Link to another page</a>
    

     

    if the user has javascript enabled the link will not go anywhere, and the jquery will run. If javascript is disabled the link will go to where the href says and the jquery will not run.

  3. Here was the code:

    <?php
         /*	Erstellt eine Tabelle aus mysql Rückgabezeilen
    	summary:	
    				Erstellt eine Tabelle aus mysql Rückgabezeilen
    				(Eine einfache Tabelle erreicht man ohne ausfüllen der Argumente, bis auf das Erste)
    
    	Argument 01:	Die Zeilen die ausgegeben werden sollen
    	Argument 02:	Die komplette Kopfzeile
    				Wird das Argument leer gelassen, so werden die Rückgabespalten als Grundlage verwendet
    	Argument 03:	Die komplette Fußzeile
    				Wird weggelassen, wenn leer
    	Argument 04 und 5:
    				colClass und colMethod steht für eine eigene Definition jeden Wertes jeder Spalter in jeder Zeile
    				colClass ist der Name der benutzerdefinierten Klasse in welcher sich die Methode befindet
    				colMethod1Arg ist der Name der benutzerdefinierten Funktion in der Klasse colClass, die den Spaltenwert bearbeitet, bevor er in der Tabellenzelle steht
    				dabei ist zu bedenken, dass diese Funktion/Methode 1 Argument hat, welches ein Array empfängt mit dem Namen der Spalte und dem Datenbankwert
    				die benutzerdefnierte Funktion sollte einen Wert zurückgeben, der den angezeigten Wert darstellt
    	Argument 06:	tableId
    				Id der Tabelle, die verwendet werden soll
    	Argument 07:	tableName
    				Name der Tabelle, der verwendet werden soll
    	Argument 08:	tableAttributes
    				Irgendwelche Attribute, wie sie auch in HTML eingetragen würden
    	Argument 09:	rowAttributes
    				Irgendwelche Attribute, die in jeder Zeile eingetragen werden sollen, wie in HTML verwendet
    	Argument 10:	cellAttributes
    				Irgendwelche Attribute, die in jeder Spalte/Zelle eingetragen werden sollen, wie in HTML verwendet
    	Argument 11:	colWrap = "|"
    				eine benutzerdefnierte Formatierung jeden Wertes jeder Zeile
    				| stellt dabei den Wert der jeweiligen Zelle dar, wie er regulär dastehen würde, (ggf. nachdem er durch die benutzerdefinierte Funktion gesendet und wieder empfangen wurde)
    */
    function makeTable($rows, $Head = "", $Foot = "", $colClass = "", $colMethod1Arg = "", $tableId = "", $tableName = "", $tableAttributes = "", $rowAttributes = "", $cellAttributes = "", $colWrap = "|") {
    	$_rows = $Head;
    
    	foreach($rows as $rowIndex => $row) {
    		if(empty($Head) && $rowIndex == 0) {
    			$_rows = "<tr>\n<td>".implode("</td><td>", array_keys($row))."</td>\n</tr>\n";
    		}
    
    		$columns = "";
    		$c = 0;
    		foreach($row as $colName => $colValue) {
    			$colValue = (empty($colClass) || empty($colMethod1Arg) ? $colValue : call_user_func(array($colClass, $colMethod1Arg), array($colName, $colValue)));
    
    			if($colWrap != "|" && !empty($colWrap)) {
    				$colValue = str_replace("|", $colValue, $colWrap);
    			}
    
    			$columns .= "<td ".
    			'id="col-'.$c.'" '.
    			'name="col_'.$colName.'" '.
    			'class="col_'.$colName.'"'.
    			(!empty($cellAttributes) ? " " : "").$cellAttributes." >".
    			$colValue."</td>";
    
    			$c++;
    		}
    
    		$_rows .= '<tr id="row-'.$rowIndex.'" name="row_'.$rowIndex.'" '.(!empty($rowAttributes) ? " " : "").$rowAttributes." >\n".$columns."\n</tr>";
    	}
    
    	$table = '<table '.
    	(!empty($tableId) ? 'id="'.$tableId.'" ' : "").
    	(!empty($tableName) ? 'name="'.$tableName.'"' : "").
    	(!empty($tableAttributes) ? " " : "").$tableAttributes." >".
    	$_rows."\n".(!empty($Foot) ? $Foot."\n" : "").
    	'</table>';
    
    	return $table;
    }
    
    /*	Erweitert die mysql Rückgabezeilen um Spalten, links oder rechts
    	summary:
    			Erweitert die mysql Rückgabezeilen um Spalten, links oder rechts
    
    	Argument 01:		rows
    					Die Zeilen, die erweitert werden sollen
    	Argument 02|03:	colConfLeft oder/und colConfRight
    					Spaltendefinitionen die links von den RückgabeSpalten angefügt werden sollen mit Zellinhalten in htmlentities
    					Beispiel
    					Spalte "Auswahl" soll in jeder Zeile eine Checkbox haben
    					das Argument sollte dann so aussehen:
    						array("Auswahl" => '<input type="checkbox" value="1">Ja</input>');
    */
    function append_columns($rows, $colConfLeft = null, $colConfRight = null) {
    	if($colConfLeft == null && $colConfRight == null)
    		return $rows;
    
    	foreach($rows as $rowIndex => $row) {
    		if($colConfLeft != null)
    			$rows[$rowIndex] = array_merge($colConfLeft, $row);
    
    		if($colConfRight != null)
    			$rows[$rowIndex] = array_merge($row, $colConfRight);
    	}
    
    	return $rows;
    }
    
    /*	Eine mysql Verbindung mit den Grundeinstellungen
    	summary:	Eine mysql Verbindung mit den Grundeinstellungen
    
    	Konstruktor-Argumente:
    
    	Argument 01:	host
    				Ort im Netzwerk, wo der Sql-Befehl angewendet werden soll
    	Argument 02:	username
    				Anmeldename an der mysql Datenbankverbindung
    	Argument 03:	password
    				Passwort zur mysql Datenbankverbindung
    	Argument 04:	fieldnamereplacements
    				Ersatztitel von Spalten
    */
    class Sql_Connection {
    	private $host = "";
    	private $username = "";
    	private $password = "";
    	private $fieldnamereplacements = null;
    
    	public function __construct($host, $username, $password, $fieldnamereplacements = null) {
    		$this->host = $host;
    		$this->username = $username;
    		$this->password = $password;
    		$this->fieldnamereplacements  = $fieldnamereplacements;
    	}
    
    	public function get_rows($sql) {
    		if($this->fieldnamereplacements != null) {
    			foreach($this->fieldnamereplacements as $find => $replace) {
    				$sql = str_replace($find, $find." AS `".$replace."`", $sql);
    			}
    		}
    		if(!mysql_connect($this->host, $this->username, $this->password))
    			die ("Keine Hostverbindung");
    
    		$result = mysql_query($sql);
    		mysql_close();
    
    		if(!$result)
    			die(mysql_error());
    
    		if(mysql_num_rows($result) == 0)
    			return array();
    
    		$rows = array();
    		for($rowIndex = 0; $row = mysql_fetch_assoc($result); $rowIndex++) {
    			$rows[$rowIndex] = $row;
    		}
    
    	return $rows;
    }
    
    }
    
    /*	Eine MySQL Abfrage mit Rückmeldung von Datenbankzeilen
    	summary:	Eine MySQL Abfrage mit Rückmeldung von Datenbankzeilen
    
    	Argument 01:	host
    				Ort, der mysql Datenbank ohne http
    	Argument 02:	user
    				Benutzername zur Anmeldung an der mysql Datenverbindung
    	Argument 03:	password
    				Passwort zur Anmeldung an der mysql Datenverbindung
    	Argument 04:	sql (ich empfehle die Spaltennamen im SQL Befehl anstelle dem * (Sternchen) zu verwenden, um Argument 05 besser verwenden zu können)
    				Der SELECT Befehl zur Wiedergabe der Datenzeilen
    	Argument 05:	fieldreplacements
    				Ersatztitel für die Spalten. Wird dieses Argument weggelassen, werden die Bezeichnung der Datenbankspalten verwendet
    	Argument 06:	sqlObject
    				Ein Variable, die die MySqlVerbindung als Objekt zurückbehält
    */
    function mysql_rows($host, $user, $password, $sql, $fieldreplacements = null, &$sqlObject = null) {
    	$sqlObject = new Sql_Connection($host, $user, $password, $fieldreplacements);
    	return $sqlObject->get_rows($sql);
    }
    ?>

     

    It seems to work here, do I need to convert the code to utf8 or something?

  4. I had a member submit a snippet with Russian characters in his/her comments, when I used highlight_string on the code, nothing came back. As soon as I removed the comments highlight_string worked fine, so I decided to translate them so they would show up on the page, and that they did.

     

    So my question: does highlight_string not support Russian, Chinese, etc. characters? If it does how can I fix it so that it will?

     

    all I am doing is this:

    // $str comes from the database
    $assign = " ... " . highlight_string($str, true) . " ... ";
    echo $assign;
    

  5. This is just me, but I like to write my code like this (not needed but this is how I like to do it), otherwise your code looks fine to me:

    	function validatePhoto($photoName, $photoApproved){
    	// Set a default return value
    	$safeImage = "NoImageAvailable_100x76.png";
    	// Check for Photo.
    	if (is_file(WEB_ROOT . 'uploads/' . $photoName)){
    		// Photo Found.
    		// Check if Approved.
    		if ($photoApproved==1){
    			// Photo Approved.
    			$safeImage = $photoName;
    		}else{
    			// Photo Pending.
    			$safeImage = "PhotoPendingApproval_100x76.png";
    		}
    	}
    	return $safeImage;
    }//End of validatePhoto

     

    I always preset my values, it is a good habit to get into, that way you know for a fact that something will be returned (unless there is a syntax error or something). When you have more complex functions/methods, where there are loops and if/else statements; if you don't preset your values your value may not return what you expect, especially if you missed adding an else statement somewhere.

  6. preg_replace() isn't doing it. Have you checked what $template is before this tag replacing runs? What are the various $keys and $values?

    actually it is, because when I woke up this morning I though why use preg_replace try str_replace instead:

     

    $template = str_replace("<!--[$key]-->", $value, $template);

     

    It works perfect! So It looks like a good night sleep may have solved the issue?!?!

  7. I am not sure what I am doing wrong, but I am doing this to replace values within a template:

     

    $template = preg_replace("/\<!--\[$key\]--\>/sU", $value, $template);

     

    foreach($this->items as $key => $value){
    $key = preg_quote($key, "/");
    if(is_string($key) && (is_string($value) || is_int($value) || is_numeric($value) || is_integer($value))){
    	$template = preg_replace("/\<!--\[$key\]--\>/sU", $value, $template);
    }
    }

     

    basically it loops through the array and replaces everything in the template.

     

    I was then looking through my site and saw this:

        $replace = array( 
            '<b></b>', 
            '<i></i>', 
            '<span style="text-decoration:underline;"></span>', 
            '<span style="font-size:px;"></span>', 
            '<span style="color:;"></span>' 
        ); 

     

    all the $1 and $2 are missing between the tags, and in the attributes, but as you can see they are still in the variables. The last thing after that foreach is an echo statement that echo's out the template and that is the very last thing to happen on the page.

     

    So why is my preg_replace removing those? I echo out the key right before it replaces and they are in there, but as soon as the replace happens, they are gone...

     

    What is causing this?

     

    Example: http://phpsnips.com/snip-41

  8. Hi,

    Try this code:

    $url = 'www.youtube.com/watch?v=aHjpOzsQ9YI';
    preg_match('/v=([a-z0-9]+)$/i', $url, $mc);
    echo $mc[1];      // aHjpOzsQ9YI

     

    That won't always work, youtube uses other characters as well.

     

    as requinix said do this:

    $url = "www.youtube.com/watch?v=aHjpOzsQ9YI";
    $pu = parse_url($url);
    // php 5.4: $query = parse_url($url)["query"];
    // other:
    $query = $pu["query"];
    $parameters = parse_str($query);
    print_r($parameters);

  9. you could change it to empy(), but that doesn't mean that the string passed to it is a real existing file.

     

    *should* and *do* are two different things, any number of errors could have gone wrong while saving the file, and the file didn't get saved, or maybe someone deleted the file without you knowing.

     

    maybe your table cell only stores 20 characters and the file was stored as 30 characters

     

    DB:  asdfghjkloiuytrewqas

    File: asdfghjkloiuytrewqashdulsd.jpg

     

    That means the file "asdfghjkloiuytrewqas" probably doesn't exist.

  10. all of the following are considered empty:

     

    "" (an empty string)

    0 (0 as an integer)

    0.0 (0 as a float)

    "0" (0 as a string)

    NULL

    FALSE

    array() (an empty array)

    var $var; (a variable declared, but without a value in a class)

     

    So really you don't even need the is_null()

     

    might also want to consider removing all spaces before passing to empty()

     

    empty: ""

    not empty: " " or "      "

     

    Edit:

     

    I am not sure if you already have the file saved, but another function to use would be file_exists if you have it saved

  11. There are sites out there where I can upload an image, and put it onto some sort of merchandise, such as: shirts, cups, mouse pads, office supplies, and any other random thing.

     

    I checked out http://cafepress.com, but was not impressed. I couldn't choose the logo placement on the item, it was in a default spot, and they didn't have too much of a selection.

     

    So, any suggestions?

  12. I guess with the "\s\s+" I could remove all space into 1 space, so that wouldn't break.

     

    But we have been going though code making sure there are semi-colons on everything in the js.

     

    I feel, if you can't minify js and css without errors (after comments are removed) then your doing something wrong.

  13. The CSS and JS I do want minified, so I don't care if they are, just can't use single line comments in the source.

     

    Okay, just input areas I would like to ignore (textarea/input)

  14. Currently I use this to "Minify" my html:

     

    $template = preg_replace("/\s\s+/", "", $template);
    $template = preg_replace("/\r|\n/isU", "", $template);
    $template = preg_replace("/\t/isU", "", $template);

     

    I just found an issue that I didn't think of when writing this, within textarea's that gets minified too. so all the places where a newline would be within the textarea is now gone and when putting default data into a textarea mulitline functionality is gone.

     

    What can I do to preserve newlines in the textarea, yet still minify?

  15. Is it me, or is this being greedy?

     

    preg_match_all("/<script.+>.+<\/script>/isU", $template, $matches);
    foreach($matches[0] as $match){
    if(!empty($match)){
    	echo "\n\n\n\n\n\n\n\n\n$match\n\n\n\n\n\n\n\n\n";
    }
    }

     

    Output:

     

    <script type="text/javascript" src="//jssnips.com/jquery/latest.js"></script><script type="text/javascript" src="//static1.phpsnips.com/js/anchorReader.js"></script>

     

    I have about 5 - 10 places where script tags are located on a page, why is it pulling 2 script tags out as one match? They should each be their own match, and those two tags should have even matched.

  16. I made a minifier (kinda), basically it removes newlines/tabs/2+ spaces in the html doc. What I would like to do is remove js comments in the html doc. BUT! I display php code on the page so I can not remove those comments.

     

    so...

     

    I would like to remove comments between the <script> and <style> tags, and ignore the ones between the <code> tags. Any suggestions on how to do this?

  17. Lets say you have a "Messaging System" on your site, and every time someone messages another member, you send out a notification to the member that received the message. Do you:

     

    A. Put the full message in the email as well

    B. Put a partial message in the email as well

    C. Just tell the member that someone messaged you and to go to the site to read the full message

    D. Other

     

    Me and another developer are having issues deciding I say C, and he says A. The reason I say C is because it will help keep the site active, and he says A because everyone else does it.

     

    What are your thoughts?

  18. It has been 5 years since I started PHP Snips, and now we/I have finally decided to give it a makeover! We also added a few new features, such as:

     

    - Download button

    - Search bar suggestions

    - Screen shots

    - Toolkit

    - Like / Dislike Comments

    - Member Profiles

    - Personal news feed

    - Follow Member

    - Contact Member

    - Settings

    - Email When Someone Comments on your code/profile

    - Email When Someone Votes on your snippet

     

    Some of those features are "Members Only Features"

     

    The old site:

    http://phpsnips.com

     

    The new site (/beta.php will be removed once we go live):

    http://beta.phpsnips.com/beta.php

     

    So, what do you think of the new site, and what other suggestions do you have?

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.