0

タイトル出力のphpコードに問題があります。

例:タイトルに「example1,example2,example3,example4,...」の ような単語がある場合このタイトルはクラウド div スタイルを拡張します。

出力.$row['title']. example1、 example2 、example3 から example1、example2、example3 までの単語をスペースで区切る必要がありますが、そうではありませんこれが起こるようにこのコードを変更するにはどうすればよいですか?

ありがとう。

<?php


function print_cloud()
{ global $use_ads_scrl; $res=""; if ($use_ads_scrl=="yes"){$res=print_cloud2();}  return $res; }

function print_cloud2()
{

global $table_ads, $HTTP_GET_VARS;

$city_sch="";
if ($HTTP_GET_VARS['city']!=""){$city_sch="and city='".$HTTP_GET_VARS['city']."' ";}

$sql_query="select * from $table_ads where (adcommkey is null or adcommkey=0) and visible=1 $city_sch
order by RAND() limit 10";

$sql_res=mysql_query("$sql_query");

$min = '10'; // Minimum font size in pixel.
$max = '22'; // Maximum font size in pixel.

$k1=""; $html_res="";
while ($row = mysql_fetch_array($sql_res)){
$k1="1";
if($row['adphotos']=='yes'){$check_ph=$photo_mark;} else {$check_ph="";}

$html_res=$html_res."
<a style='font-size:".rand($min,$max)."px; font-family:tahoma,sans-serif;'    
    class=\"tag_cloud\" 
        href='index.php?md=details&id= ".$row['idnum']." '> ".$row['title']." </a> 
";


}

$html_res="
$html_res
";

if ($k1==""){$html_res="";}

return $html_res;
}

?>
4

4 に答える 4

3

これには str_replace を使用できます。

echo str_replace(",", ", ", $the_string);
于 2012-08-24T12:19:03.110 に答える
2

文字列をカンマで分割し、カンマとスペースを接着剤として使用して再度結合します。

 $row['title'] = implode( ', ', explode( ',', .$row['title'] ) );
于 2012-08-24T12:18:46.683 に答える
0
    $txt = $row['title'];   
    $txt = explode(",", $txt);
    foreach($txt as $key => $value) {
       echo $value.", ";
    }
于 2012-08-24T12:20:57.833 に答える
0

私の答えは単純すぎて正しくないように思えますが、これで終わりです。

このコードを変更します。

$html_res=$html_res."
<a style='font-size:".rand($min,$max)."px; font-family:tahoma,sans-serif;'    
    class=\"tag_cloud\" 
        href='index.php?md=details&id= ".$row['idnum']." '> ".$row['title']." </a> 
";

このコードに:

$html_res=$html_res."
<a style='font-size:".rand($min,$max)."px; font-family:tahoma,sans-serif;'    
    class=\"tag_cloud\" 
        href='index.php?md=details&id= ".$row['idnum']." '> ".$row['title'].",</a> ";

更新された完全なコードは以下のとおりです。

<?php


function print_cloud()
{ global $use_ads_scrl; $res=""; if ($use_ads_scrl=="yes"){$res=print_cloud2();}  return $res; }

function print_cloud2()
{

global $table_ads, $HTTP_GET_VARS;

$city_sch="";
if ($HTTP_GET_VARS['city']!=""){$city_sch="and city='".$HTTP_GET_VARS['city']."' ";}

$sql_query="select * from $table_ads where (adcommkey is null or adcommkey=0) and visible=1 $city_sch
order by RAND() limit 10";

$sql_res=mysql_query("$sql_query");

$min = '10'; // Minimum font size in pixel.
$max = '22'; // Maximum font size in pixel.

$k1=""; $html_res="";
while ($row = mysql_fetch_array($sql_res)){
$k1="1";
if($row['adphotos']=='yes'){$check_ph=$photo_mark;} else {$check_ph="";}

$html_res=$html_res."
<a style='font-size:".rand($min,$max)."px; font-family:tahoma,sans-serif;'    
    class=\"tag_cloud\" 
        href='index.php?md=details&id= ".$row['idnum']." '> ".$row['title'].",</a> ";


}

$html_res="
$html_res
";

if ($k1==""){$html_res="";}

return $html_res;
}

?>
于 2012-08-24T12:35:38.343 に答える