PHP association Link Add Method _php tutorial

Source: Internet
Author: User

How to add a PHP association link


In order to optimize the inner chain, we need to add the content of the key link, that content if the link is added, how to add it?

Method One: Manually edit the Add

Method Two: Use the program to output content, without affecting the background content editing.

Here's how PHP automatically adds an associated link method and an example to the article content:

Keylinks Function Method:

Parameter one: what to work on

Parameter two: number of replacements

Return results: Processed content

Header ("Content-type:text/html;charset=utf-8"); Set encoding

$linkdatas =array (

Array (' Front-end development ', ' http://blog.kgula.com '),

Array (' Front-end design ', ' http://blog.kgula.com '),

Array (' Web Front end ', ' http://blog.kgula.com '),

Array (' Front-end blog ', ' http://blog.kgula.com '),

);

echo "before replacing
";

echo $str = ' web front-end development-focus on website front-end design and Web user experience. Front-end development, focus on web front-end development, focus on Web user experience, focus on the latest and best front-end design resources and front-end development technology professional front-end blog ';

echo "
After replacement
";

echo $str =keylinks ($STR, 2);

/**

* Associated keyword substitution

* @param txt $string original string

* @param replacenum $int Number of replacements

* @return String returns strings

*/

function Keylinks ($txt, $replacenum = ") {

Global $linkdatas;

if ($linkdatas) {

$word = $replacement = Array ();

foreach ($linkdatas as $v) {

$word 1[] = '/(?! ()/s ';

$word 2[] = $v [0];

$replacement [] = '. $v [0]. '';

}

if ($replacenum! = ") {

$txt = Preg_replace ($word 1, $replacement, $txt, $replacenum);

} else {

$txt = Str_replace ($word 2, $replacement, $txt);

}

}

return $txt;

}

http://www.bkjia.com/PHPjc/1049990.html www.bkjia.com true http://www.bkjia.com/PHPjc/1049990.html techarticle PHP Associated Link Add method in order to optimize the inner chain, we need to add the content on the key link, that content if you add links, how to add it? Method One: Manually edit Add ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.