简体   繁体   English

两个单词之间的空格和链接问题

[英]Space between two words and link issue

First of all, i want to say that i searched a solution for this problem but i couldn't find. 首先,我想说的是我已经找到了解决此问题的方法,但找不到。

The problem is ; 问题是 ; in my database i have more than 2000 rows and some of them has two words and after fetching this data from db i'm using this words as a link. 在我的数据库中,我有2000多个行,其中一些行有两个单词,从db获取此数据后,我将这些单词用作链接。 For example ; 例如 ;

<a href=/'.$row['word'].'.html >'.$row['word'].'</a>
db word = one

This code works with one word perfectly and result is : site.com/one.html 该代码可以完美地使用一个单词,结果是: site.com/one.html

but if i have a value in db like "one two" and if i use this code again 但是,如果我在数据库中有一个“一二”的值,并且如果我再次使用此代码,

<a href=/'.$row['word'].'.html >'.$row['word'].'</a>
db word = one two

then the result is: site.com/one 那么结果是: site.com/one

but actually it should be : site.com/one+two.html or at least, it must add the second word. 但实际上它应该是: site.com/one+two.html或至少它必须添加第二个单词。

on the page i see the "one two" words but when i click on it, it goes to site.com/one 在页面上,我看到“一二”字,但是当我单击它时,它转到site.com/one

Thanks 谢谢

您应该对字符串进行urlencoding

'<a href="/' . urlencode($row['word']) . '.html" >' . $row['word'] . '</a>'

You could also use a custom character as word divider 您也可以使用自定义字符作为分词器

$url = implode('-',explode(" ",$row['word']));
'<a href="/' . urlencode($url) . '.html" >' . $row['word'] . '</a>'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM