我在网站上有一个特定的文本,让我们说"lollypops",我想用"marshmellows"替换这个字符串的所有出现.问题是我不知道文本的确切位置.我知道我可以这样做:
$(body).html($(body).html().replace('lollypops', 'marshmellows'));
Run Code Online (Sandbox Code Playgroud)
这可能会有效,但我需要尽可能少地重写HTML,所以我想的是:
class,但不是src在示例中,我会有这样的结构
<body>
<div>
<div>
<p>
<h1>
<a>lollypops</a>
</h1>
</p>
<span>lollypops</span>
</div>
</div>
<p>
<span class="lollypops">Hello, World!</span>
<img src="/lollypops.jpg" alt="Cool image" />
</p>
<body>
Run Code Online (Sandbox Code Playgroud)
在这个例子中,每次出现的"lollypops"都会被替换,只会<img src="...保持不变,而实际操作的唯一元素将是<a>两个<span>s.
有人知道怎么做这个吗?
我正在尝试使用PHPMailer发送SMTP电子邮件,但我不断收到此错误消息,任何想法如何摆脱它?
我正在尝试通过端口465上的SSL连接.
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
Notice: fputs() [function.fputs]: send of 18 bytes failed with errno=32 Roura p?erušena (SIGPIPE) in /home/www/amazonek.cz/subdomains/library/PHPMailer_v5.1/class.smtp.php on line 494
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
Notice: fputs() [function.fputs]: send of 12 bytes failed with errno=32 Roura p?erušena (SIGPIPE) in /home/www/amazonek.cz/subdomains/library/PHPMailer_v5.1/class.smtp.php on line 212
SMTP -> ERROR: AUTH not accepted from server:
SMTP Error: Could not authenticate.
Run Code Online (Sandbox Code Playgroud)
我的代码: …
最近我遇到了几种语言的bug /功能.我对它是如何引起的有一个非常基本的了解(我想要一些详细的解释),但是当我想到多年来我必须犯下的所有错误时,问题是如何确定" 嘿,这可能会导致一个荒谬的bug,我最好使用任意精度函数 ",其他语言确实有这个bug(和那些没有,为什么).另外,为什么0.1 + 0.7这样做,而0.1 + 0.3没有,还有其他众所周知的例子吗?
PHP
//the first one actually doesn't make any sense to me,
//why 7 after typecast if it's represented internally as 8?
debug_zval_dump((0.1+0.7)*10); //double(8) refcount(1)
debug_zval_dump((int)((0.1+0.7)*10)); //long(7) refcount(1)
debug_zval_dump((float)((0.1+0.7)*10)); //double(8) refcount(1)
Run Code Online (Sandbox Code Playgroud)
蟒蛇:
>>> ((0.1+0.7)*10)
7.9999999999999991
>>> int((0.1+0.7)*10)
7
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
alert((0.1+0.7)*10); //7.999999999999999
alert(parseInt((0.7+0.1)*10)); //7
Run Code Online (Sandbox Code Playgroud)
红宝石:
>> ((0.1+0.7)*10).to_i
=> 7
>>((0.1+0.7)*10)
=> 7.999999999999999
Run Code Online (Sandbox Code Playgroud) 目标很简单,但很不寻常.我写了一个数据库自动修复脚本(因为其中一个表不时崩溃,可能是由于非常大量的插入和不断删除),我想测试它.问题是,我需要故意崩溃一个表,我不知道如何.有什么建议?
我有一个带&符号值的输入元素:
<input type="checkbox" value="Biografie, životopisy, osudy, Domácí rock&pop" />
Run Code Online (Sandbox Code Playgroud)
当我尝试通过ajax请求发送它时:
$.ajax({
type: "POST",
url: "/admin/kategorie/add/link.json",
data: "id="+id+"&value="+value+"&type="+type,
error: function(){alert('Chyba! Reloadn?te prosím stránku.');}
});
Run Code Online (Sandbox Code Playgroud)
实际发送的帖子数据是:
id: 1
pop:
type: e
value: Biografie, životopisy, osudy, Domácí rock
Run Code Online (Sandbox Code Playgroud)
*请注意,数据中的所有变量都已定义,值包含$(thatInputElement).attr('value').
我怎样才能&正确逃脱,以便后期字段value包含Biografie, životopisy, osudy, Domácí rock&pop?
我有一个表示表单的结构,我想使用RecursiveIterator迭代它.问题是这只会返回顶级问题.我究竟做错了什么?
整体形式:
class Form implements RecursiveIterator{
private $id;
private $caption;
private $other_text;
private $questions = array();
private $current;
private function __construct(DibiRow $row){
$this->id = $row->id;
$this->caption = $row->caption;
$this->other_text = $row->other_text;
$this->loadQuestions();
}
private function loadQuestions(){
$questions = dibi::query('SELECT * FROM cyp_questions WHERE form_id = %i AND parent_id IS NULL', $this->id);
while($question = $questions->fetch()) $this->questions[] = new Question($question->question_id, $question->type, $question->caption, $question->other_text, $question->triggers_unique == 1);
}
/**
* @throws InvalidArgumentException
* @param $id
* @return Form
*/
public static function loadById($id){ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PHP解压缩14MB存档,代码如下:
$zip = zip_open("c:\kosmas.zip");
while ($zip_entry = zip_read($zip)) {
$fp = fopen("c:/unzip/import.xml", "w");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
fwrite($fp,"$buf");
zip_entry_close($zip_entry);
fclose($fp);
break;
}
zip_close($zip);
}
Run Code Online (Sandbox Code Playgroud)
它在我的本地主机上失败,128MB内存限制与经典" Allowed memory size of blablabla bytes exhausted".在服务器上,我有16MB的限制,有没有更好的方法来做到这一点,以便我可以适应这个限制?我不明白为什么这需要分配超过128MB的内存.提前致谢.
解决方案: 我开始以10Kb块的形式读取文件,问题解决了峰值内存使用率为1.5MB.
$filename = 'c:\kosmas.zip';
$archive = zip_open($filename);
while($entry = zip_read($archive)){
$size = zip_entry_filesize($entry);
$name = zip_entry_name($entry);
$unzipped = fopen('c:/unzip/'.$name,'wb');
while($size > 0){
$chunkSize = ($size > 10240) ? 10240 : $size;
$size -= $chunkSize;
$chunk = zip_entry_read($entry, $chunkSize);
if($chunk !== false) …Run Code Online (Sandbox Code Playgroud) 这个想法很简单 - 我有两个表,类别和产品.
分类:
id | parent_id | name | count
1 NULL Literature 6020
2 1 Interesting books 1000
3 1 Horrible books 5000
4 1 Books to burn 20
5 NULL Motorized vehicles 1000
6 5 Cars 999
7 5 Motorbikes 1
...
Run Code Online (Sandbox Code Playgroud)
产品介绍:
id | category_id | name
1 1 Cooking for dummies
2 3 Twilight saga
3 5 My grandpa's car
...
Run Code Online (Sandbox Code Playgroud)
现在显示时,父类别包含所有子类别的所有产品.任何类别都可能有子类别.表结构中的count字段包含(或至少我希望它包含)此特定类别中显示的所有产品的计数.在前端,我使用简单的递归函数选择所有子类别,但是我不太确定如何在SQL过程中执行此操作(是的,它必须是SQL 过程).这些表包含有关hundread类别的任何种类,有超过10万种产品.
有任何想法吗?
我使用UNION ALL两个表创建了一个MySQL视图,这样我就可以在这些表中获得相同数据的相同列名(即tbl1.author2 AS translator... tbl2.translator AS translator)等等,问题是当我尝试从该视图中选择一些东西时,数据来自BLOB,而不是原始值.
视图定义是:
SELECT e.id AS prod_id,
e.price_vat AS price_vat,
e.product AS title,
e.authors AS author,
e.isbn AS isbn,
e.ean AS ean,
e.page_count AS page_count,
e.publishers AS publishers,
e.issue_year AS issue_year,
'e' AS type
FROM ama_euromedia_products AS e
UNION ALL
SELECT
k.publishers AS publishers,
DATE_FORMAT(k.publication_date, '%Y') AS issue_year,
k.ean AS ean,
k.number_of_pages AS page_count,
k.author AS author,
k.isbn AS isbn,
k.title_full AS title,
k.price_amount AS price_vat,
k.internal AS …Run Code Online (Sandbox Code Playgroud) 在PHP中有函数array_values
$array2 = array_values($array1);
Run Code Online (Sandbox Code Playgroud)
$array2具有相同的值$array1,但关键是从
0到sizeof($array1) - 1.是否可以从旧密钥映射到新密钥?
编辑.我将在一个例子中解释:
$array1 = array( 'a' => 'val1', 'b' => 'val1');
$array2 = array_values( $array1 );
Run Code Online (Sandbox Code Playgroud)
所以现在array2有下一个值
$array2[0] = 'val1'
$array2[1] = 'val2'
Run Code Online (Sandbox Code Playgroud)
如何获得array3:
$array3['a'] = 0
$array3['b'] = 1
Run Code Online (Sandbox Code Playgroud)