php - 如何将函数的变量放入此动作脚本?

时间:2011-07-13 22:08:34

标签: php

我在下面有变量$ test1和$ test2 ..如何在下面输入网站名称的地方更换它们?我很沮丧..我正在使用wordpress作为cms ..

    <?php
$homepage = file_get_contents('http://www.macsiam.com/sites.php');


preg_match_all('%\'http://([^./]+).[^.]+\.[a-z]{2,4}\'%i', $homepage, $domains, PREG_PATTERN_ORDER);
// $domains[0] is an array of matched full URLs (http://whatever.wherever.com/page.php)
// $domains[1] is an array of matched subdomains (whatever)

$test1 = $domains[1][0];
$test2 = $domains[1][1];

echo $test1;
echo '<br>';
echo $test2;

?>

<?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
<table class="form-table">
    <tr class="form-field form-required">
      <th scope="row"><?php _e( 'Site Address' ) ?></th>
      <td>
      <?php if ( is_subdomain_install() ) { ?>
      <input name="blog[domain]" type="text" class="regular-text" title="<?php _e( 'Domain' ) ?>"/>.<?php echo preg_replace( '|^www\.|', '', $current_site->domain );?>
      <?php } else {
        echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php _e( 'Domain' ) ?>"/>
      <?php }
      echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>';
      ?>
      </td>
    </tr>
    <tr class="form-field form-required">
      <th scope="row"><?php _e( 'Site Title' ) ?></th>
      <td><input name="blog[title]" type="text" class="regular-text" title="<?php _e( 'Title' ) ?>"/></td>
      </tr>
      <tr class="form-field form-required">
        <th scope="row"><?php _e( 'Admin Email' ) ?></th>
        <td><input name="blog[email]" type="text" class="regular-text" title="<?php _e( 'Email' ) ?>"/></td>
      </tr>
      <tr class="form-field">
        <td colspan="2"><?php _e( 'A new user will be created if the above email address is not in the database.' ) ?><br /><?php _e( 'The username and password will be mailed to this email address.' ) ?></td>
      </tr>
    </table>
    <?php submit_button( __('Add Site'), 'primary', 'add-site' ); ?>

<form method="post" action="<?php echo network_admin_url('site-new.php?action=add-site'); ?>">

1 个答案:

答案 0 :(得分:0)

我看不出你要放在哪里。我甚至不明白你想要完成什么。但我会在这里做一些猜测。最不明智的是,您要将两个要替换的变量描述为数组(而不是字符串),但是您希望在站点名称(通常是字符串)的位置使用这些数组。

如果您只是想将变量内容添加到页面上的特定位置,那么您只需创建变量,然后在模板中将其回显到您希望的位置。

<div class="site-name"><?php echo $test1; ?></div>

如果你真的想要网站名称,Wordpress就有这个功能。它叫做wp_title。

<div class="site-name"><?php wp_title(); ?></div>

http://codex.wordpress.org/Function_Reference/wp_title

除此之外,您可以将输出包装在JavaScript标记中,并将值设置为Javascript(JS)变量值。然后你可以使用JS把它放在你想要的页面上。

如果您正在尝试做其他事情,那么我建议更具体地说明数据A是什么(如果它直接在页面上,应该最终成为字符串)。给我们一个数据本身的例子(具体来说,比如$ title ='我的破坏网站';)。然后告诉我们你想要最终的结果。也许在一些div之间。也许作为隐藏的表单输入或表单动作参数。如果你需要在页面上编码一个数组,那么告诉我们你想如何使用它以及为什么它必须在页面上。