php - 如何将函数的变量放入此操作脚本中?
我下面有变量 $test1 和 $test2..我怎样才能让它们替换您在下面输入站点名称的位置? 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;
?>
我很沮丧..我正在使用wordpress作为
<?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'); ?>">
i have the variables $test1 and $test2 below.. how can i get them to replace where you enter the site name below? im so frustrated.. i am using wordpress as a 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;
?>
to
<?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'); ?>">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白你想把这些放在哪里。我什至不明白你到底想实现什么目标。但我会在这里做一些猜测。最没有意义的是,您将要替换的两个变量描述为数组(而不是字符串),但您希望使用这些数组来代替站点名称(通常是字符串)。
如果您尝试将变量内容添加到页面上的特定位置,那么您只需创建变量并在模板中将其回显到您想要的位置。
如果您确实想要网站名称,Wordpress 有一个功能。它的名字叫wp_title。
http://codex.wordpress.org/Function_Reference/wp_title
除此之外,您可以包装输出在 JavaScript 标签中并将值设置为 Javascript (JS) 变量值。然后你可以使用 JS 将其动态放置在页面上你想要的位置。
如果您尝试做其他事情,那么我建议更具体地说明数据 A 是什么(如果直接在页面上显示,则最终应该是字符串)。给我们一个数据本身的例子(具体的,比如 $title = 'My Broken site';)。然后告诉我们您希望这一切以什么方式结束。也许在一些div之间。也许作为隐藏的表单输入或表单操作参数。如果您需要将数组编码到页面上,请告诉我们您想如何使用它以及为什么它必须出现在页面上。
I don't see where you are trying to place any of this. I don't even understand exactly what you are trying to accomplish. But I will make a few guesses here. What makes the least amount of sense is the fact that you describe both of the variables you want to substitute in as arrays (not strings) but you want to use these arrays in the place of a site name (which is commonly a string).
If you are trying to just add the variable contents to a specific place on the page then you would just create the variable and in the template echo it where you want it to go.
If you actually want the site name, Wordpress has a function for that. Its called wp_title.
http://codex.wordpress.org/Function_Reference/wp_title
Other than that you can wrap the output in JavaScript tags and set the value as a Javascript (JS) variable value. Then you can use JS to put it where you want it to go on the page on the fly.
If you are trying to do something else then I recommend being more specific what data A is (should end up being a string if it is going on a page directly). Give us an example of the data itself (specific, such as $title = 'My broke site';). Then show us where you want this to end up. Maybe between some divs. Maybe as a hidden form input or a form action param. If you need an array encoded onto the page then tell us how you want to use that and why it has to be on the page.