optimization codes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
_Boogie_
Forum Newbie
Posts: 3
Joined: Sun Dec 27, 2009 5:53 am

optimization codes

Post by _Boogie_ »

Hello!
I developed a PHP site that gives customer's the option to put his own "seo tags" on any page of the site, whether that page is an article page or the main page.
For example to put his tags on http :// www. site .com/Florida-football-coach-Meyers-resigns.html, he should create a file named Florida-football-coach-Meyers-resigns.txt in the "SEO" folder on the server. The script will search into the seo folder for a file named like the page that is going to be displayed and if there is one, it will display the content of the file between the tags <head> and </ head>.

But now, the customer has found another way to control these tags.

For example: he wants the script to establish the most relevant words. In the "seo tags" file on the server he wants just to specify to the script that he wants the first 5 most common words in the page that is going to be displayed. (in this case he proposed the code: [words4] => first 4 most common words. But he can also use [words+] case in which all words will be displayed in descending order of number of appearances )
His proposed codes then become increasingly complex (a code for most common phrases or combinations of several codes) and things got complicated.
Can you give me any idea that can help me developing this feature?

Sample file with tags for page Florida-football-coach-Meyers-resigns.html

Code: Select all

<title>Florida football coach Meyers resigns</ title>
 
<META Name="keywords" CONTENT="[expressions5@2-3]">
<META Name="description" CONTENT="[2/1][words+][expressions+@2-3]">
 
* [expressions5@2-3] means first 5 most common phrases of 2 or 3 words
* [2/1][words+][expressions+@2-3] means a combination of the most common words and common phrases of 2 or 3 words displayed in the order [2 / 1] ( two common words followed by one common expression and so on)
Sorry for my poor english.
I hope you'll understand what I'm trying to say.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: optimization codes

Post by AbraCadaver »

The logic for selecting the phrases would depend upon how the txt file is constructed. If you can show an example that would help. I would however, recommend to the customer that you go for a simpler syntax that can be easily used by PHP, such as:

Code: Select all

<META Name="keywords" CONTENT="[--expression(5, '2-3')--]">
<META Name="description" CONTENT="[--expression(5, '2-3')--][--words()--]">
Now a simple preg_replace() can turn [--expression(5, '2-3')--] into <?php expression(5, '2-3'); ?>. All you need to do is write the expressions() and words() functions. Also, rather than specifying the order, just put them in the order that you want.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
_Boogie_
Forum Newbie
Posts: 3
Joined: Sun Dec 27, 2009 5:53 am

Re: optimization codes

Post by _Boogie_ »

Thanks for the idea.
I managed to write the functions but now I have a problem with the eval() function.
The code in the box below displays <meta name="keywords" content="'.($s->Limit($s->Keywords($BODY),1)).'" />
instead of <meta name="keywords" content="random" /> (because $s->Limit($s->Keywords($BODY),1)) means first keyword from body).

Code: Select all

<?php
    
    require("class.php");
    $s=new seo();
    $s->MinWordLenght=4;
    
    $BODY="some random text random text random";
    
    $code='<meta name="keywords" content="%Limit(Keywords({BODY}),1)%" />';
    //This works:  $cod='Limit(Keywords({BODY}),1)';
    $code=str_replace("<","<",$code);
    $code=str_replace(">",">",$code);
    $code=trim($code);
    $code=ereg_replace("\{([A-Z]+)\}","$\\1",$code);
    $code=ereg_replace("\{([A-Z]+)\[([0-9]+)\]\.([a-z]+)\}",'$\\1[\\2]["\\3"]',$code);
    $code=ereg_replace("([A-Z]{1}[a-z]+\()","\$s->\\1",$code);
    $code=str_replace('"%',"\"'.(",$code);
    $code=str_replace('%"',").'\"",$code);
    //$code=str_replace("<","<",$code);
    //$code=str_replace(">",">",$code);
    
    eval('echo $code;');
    
?>
It's obviously a problem regarding the quotes but I didn't manage to fix it.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: optimization codes

Post by AbraCadaver »

I think this will work with your current code:

Code: Select all

   eval("echo '$code';");
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
_Boogie_
Forum Newbie
Posts: 3
Joined: Sun Dec 27, 2009 5:53 am

Re: optimization codes

Post by _Boogie_ »

Thank you so much for your help!
Post Reply