我正在寻找一个PHP脚本或类,可以缩小我的PHP页面html输出像谷歌页面速度.
我怎样才能做到这一点?
可能重复:
如何在PHP中从数组创建逗号分隔列表?
我的数组看起来像这样:
Array
(
[0] => lorem
[1] => ipsum
[2] => dolor
[3] => sit
[4] => amet
)
Run Code Online (Sandbox Code Playgroud)
如何使用php将其转换为这样的字符串?
$string = 'lorem, ipsum, dolor, sit, amet';
Run Code Online (Sandbox Code Playgroud) 实际代码如下所示:
if (file_exists($filename)) {echo $player;
} else {
echo 'something';
Run Code Online (Sandbox Code Playgroud)
但即使没有从网址调用id,它也会显示播放器
我需要这样的东西:
check if $filename exists and $id it is not empty then echo $player
if else echo something else
Run Code Online (Sandbox Code Playgroud)
我检查$ id是否为空
if(empty($id)) echo "text";
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将它们两者结合起来
有人能帮助我吗?
感谢您的所有代码示例,但我仍有问题:
我如何检查$ id 是否为空,然后回显其余的代码
我在考虑这样的事情:
`post_modified` int(11) NOT NULL DEFAULT UNIX_TIMESTAMP (NOW ()) ON UPDATE UNIX_TIMESTAMP (NOW ()),
Run Code Online (Sandbox Code Playgroud)
但是这段代码不起作用.
我使用此代码来获取有关某个 ID 的信息
$sql = dbquery("SELECT * FROM `videos` WHERE `id` = ".$local_id." ");
while($row = mysql_fetch_array($sql)){
$video_id = $row["id"];
$video_title = $row["title"];
}
Run Code Online (Sandbox Code Playgroud)
假设一个页面的链接是 example.com/video.php?id=34
如何根据当前 id 获取下一个和上一个 $video_id 和 $video_title ?
一个问题是我不能将当前 id 的值增加或减少 1,因为 35 或 33 可能同时被删除......
我怎样才能做到这一点?
//编辑
我有一个很大的问题:上一个链接将我发送到正确的链接,但下一个链接总是将我发送到数据库中添加的最后一个视频。
如果我转到数据库中添加的最后一个或第一个视频,我会收到错误消息,因为没有添加更多的下一个和上一个视频。
假设我有这个json数据.如何将"标签"转换为类似的字符串
$tags = "Rihanna, We, Found, Love, (Explicit), Def, Jam, Records, Pop"; ?
{ "apiVersion" : "2.1",
"data" : { "items" : [ { "accessControl" : { "autoPlay" : "allowed",
"comment" : "allowed",
"commentVote" : "allowed",
"embed" : "allowed",
"list" : "allowed",
"rate" : "allowed",
"syndicate" : "allowed",
"videoRespond" : "allowed"
},
"aspectRatio" : "widescreen",
"category" : "Music",
"tags" : [ "Rihanna",
"We",
"Found",
"Love",
"(Explicit)",
"Def",
"Jam",
"Records",
"Pop"
],
"title" : "Rihanna - We Found Love ft. Calvin …Run Code Online (Sandbox Code Playgroud) 变量看起来像这样:
$keywords = 'key1, key2, key3, key4';
Run Code Online (Sandbox Code Playgroud)
我如何创建链接,如:
<a href="../tag/key1">key1</a>, <a href="../tag/key2">key2</a>, <a href="../tag/key3">key3</a>, <a href="../tag/key4">key4</a>
Run Code Online (Sandbox Code Playgroud)
使用PHP?
//编辑
如果用$定义了怎么办?
$keywords = 'key1, keyword two, key3, key four';
Run Code Online (Sandbox Code Playgroud)
甚至其他订单?
<a href="../tag/key1">key1</a>, <a href="../tag/keyword+two">keyword two</a>, <a href="../tag/key3">key3</a>, <a href="../tag/key+four">key four</a>
Run Code Online (Sandbox Code Playgroud)
我的意思是,如果其中一个'关键字'由两个单词组成,则在链接处添加一个"+"符号
怎么做到这一点?
我有这个代码,但没有工作,我不知道为什么...
function link_next($local_id, $link_type) {
if ( !is_numeric($local_id) ) die();
elseif ($link_type = 'a-href') { $something = 'a-href'; }
elseif ($link_type = 'link-rel') { $something = 'link-rel'; }
else { $something = 'blablabla'; }
return $local_id.'-'.$something;
}
$id ='14678';
echo link_next($id, 'link-rel');
Run Code Online (Sandbox Code Playgroud)
//编辑
该功能始终显示14678-a-href
让我说我检查一下
$strig = "red-hot-chili-peppers-californication";
Run Code Online (Sandbox Code Playgroud)
已存在于我的数据库中:
$query = dbquery("SELECT * FROM `videos` WHERE `slug` = '".$strig."';");
$checkvideo = dbrows($query);
if($checkvideo == 1){
// the code to be executed to rename $strig
// to "red-hot-chili-peppers-californication-2"
// it would be great to work even if $string is defined as
// "red-hot-chili-peppers-californication-2" and
// rename $string to "red-hot-chili-peppers-californication-3" and so on...
}
Run Code Online (Sandbox Code Playgroud)
我想这样做是为了更友好的网址结构创建独特的slu ..
谢谢.
让我们说我的字符串:
$string = 'lorem, ipsum, dolor, sit, amet, ';
Run Code Online (Sandbox Code Playgroud)
要么 $string = 'lorem, ipsum, dolor, sit, amet,';
如何将其转换为这样的东西?
$string = 'lorem, ipsum, dolor, sit, amet';
Run Code Online (Sandbox Code Playgroud)
//该字符串由以下代码生成:
$count = count($taglist);
for ($i = 0; $i < $count; $i++) {
$videoData['tags'] .= $taglist[$i].', ';
}
Run Code Online (Sandbox Code Playgroud) 我现在使用这样的东西,但是我收到了很多错误......
$video_id = $_GET['url'];
$video_id = str_replace('http://www.youtube.com/watch?v=','',$video_id);
$video_id = str_replace('&feature=related','',$video_id);
$video_id = str_replace('&feature=fvwrel','',$video_id);
$video_id = str_replace('&hd=1','',$video_id);
$video_id = str_replace('&feature=relmfu','',$video_id);
$video_id = str_replace('&feature=channel_video_title','',$video_id);
$video_id = str_replace('&feature=list_related','',$video_id);
$video_id = str_replace('&playnext=1','',$video_id);
$video_id = str_replace('_player','',$video_id);
Run Code Online (Sandbox Code Playgroud)
问题是youtube有'&feature ='和其他人的多个url变量
我想从youtube网址中提取的唯一内容是唯一的视频ID
例如://www.youtube.com/watch?v = lgT1AidzRWM&feature = related
在id或之前没有任何内容
有人可以帮我搞定吗?
<?
$sql = dbquery("SELECT `id`, `title`, `description` FROM `content` LIMIT 0,12 ");
while ($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$title = $row["title"];
$description = $row["description"];
$content = '
<div class="description-box">
<p>page id: ' . $id . '</p>
<p>' . $title . '</p>
<p>' . $description . '</p>
</div>';
}
echo $content;
?>
Run Code Online (Sandbox Code Playgroud)
// notice:div class ="description-box"
//如何在每3个输出div之后用以下代码替换:div class ="description-box nopadding"?
html生成代码示例:
<div class="description-box nopadding">
// content
</div>
<div class="description-box">
// content
</div>
<div class="description-box">
// content
</div>
<div class="description-box"> …Run Code Online (Sandbox Code Playgroud) php ×11
mysql ×4
string ×3
if-statement ×2
arrays ×1
echo ×1
file-exists ×1
html ×1
hyperlink ×1
json ×1
minify ×1
str-replace ×1
variables ×1