我将信息分散在几个数据库中,并希望使用PHP将所有信息放到一个网页上.我想知道如何连接到单个PHP网页上的多个数据库.
我知道如何使用以下方法连接到单个数据库:
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
Run Code Online (Sandbox Code Playgroud)
但是,我可以使用多个"mysql_connect"命令来打开其他数据库,如果我连接了多个数据库,那么PHP如何知道我希望从中获取信息的数据库.
我正在寻找一种方法从字符串变量中拉出前100个字符以放入另一个变量进行打印.
有没有可以轻松完成此功能的功能?
例如:
$string1 = "I am looking for a way to pull the first 100 characters from a string variable to put in another variable for printing.";
$string2 = 100charfunction($string1);
print $string2
Run Code Online (Sandbox Code Playgroud)
要得到:
I am looking for a way to pull the first 100 characters from a string vari
Run Code Online (Sandbox Code Playgroud) 我之前在这里问过类似的问题,但我需要知道这个小调整是否可行.我想将一个字符串缩短为100个字符并使用$small = substr($big, 0, 100);它.但是,这只需要前100个字符,并不关心它是否会破坏一个单词.
有没有办法接受一个字符串的前100个字符但确保你不会破坏一个字?
例:
$big = "This is a sentence that has more than 100 characters in it, and I want to return a string of only full words that is no more than 100 characters!"
$small = some_function($big);
echo $small;
// OUTPUT: "This is a sentence that has more than 100 characters in it, and I want to return a string of only"
Run Code Online (Sandbox Code Playgroud)
有没有办法用PHP做到这一点?
如何在运行完成后将PHP函数转到特定网站?
例如:
<?php
//SOMETHING DONE
GOTO(http://example.com/thankyou.php);
?>
Run Code Online (Sandbox Code Playgroud)
我真的很喜欢以下......
<?php
//SOMETHING DONE
GOTO($url);
?>
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情:
<?php
//SOMETHING DONE THAT SETS $url
header('Location: $url');
?>
Run Code Online (Sandbox Code Playgroud) 使用新的Diggbar,您可以放在http://digg.com当前所在的任何URL之前,它将创建一个Digg短URL.我只是假设他们通过modrewrite做到这一点(虽然我不确定,因为我是新手).
这是怎么做到的?在我尝试使用我正在处理的网站时,我觉得它爆炸了.
我希望能够做到以下几点:
http://example.com/http://stackoverflow.com/question/ask
Run Code Online (Sandbox Code Playgroud)
并有一个modrewrite,允许这样做
http://example.com/index.php?url=http://stackoverflow.com/question/ask
Run Code Online (Sandbox Code Playgroud)
但是当我使用这个modrewrite时:
RewriteEngine on
RewriteRule ^([A-Za-z0-9]+)$ /message.php?id=$1 [L]
Run Code Online (Sandbox Code Playgroud)
它不起作用.我究竟做错了什么?
我想知道如何将我的index.php主页分解为多个php页面(即header.php,footer.php)并使用这些单独的php页面构建一个工作的index.php页面.我知道WordPress使用不同的功能,如:
GetHeader();
GetFoodter();
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用这些功能时,它会出错.我猜它们不是PHP的本机函数.
我需要做什么才能获得此功能?
我有一个变量,它由一个表格中的POST调用定义,并将其输入到文本字段中.有没有办法将此变量转换为整数?
从形式:
Lenght: <input name="length" value="10" type="text" id="lenght" size="2" />
Run Code Online (Sandbox Code Playgroud)
从PHP代码:
$length = $_POST['lenght'];
$url = substr($url, 0, $length);
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用,我认为它不起作用的唯一原因是因为$ lenght被定义为文本而不是整数.
有没有人修改过WordPress安装中的"post-new.php"文件?
我想修改这个页面的外观,包括我在博客文章中标准包含的部分,我只是不知道它是否可行/容易/值得我花时间.
我是否应该找到另一个允许像Drupal那样进行更多修改的CMS?
我如何从输入到表单中的长字符串中提取基本URl?
示例:用户输入:http://stackoverflow.com/question/ask/asdfasneransea
程序只需要:http://stackoverflow.com而不是/question/ask/asdfasneransea
使用PHP执行此操作的简单方法是什么?