我需要一个正则表达式(将在ZF2路由中使用,我相信它使用php的preg_match)匹配除特定字符串之外的任何内容.
例如:我需要匹配除"红色","绿色"或"蓝色"之外的任何内容.
我目前有正则表达式:
^(?!red|green|blue).*$
test -> match (correct)
testred -> match (correct)
red -> doesn't match (correct)
redtest -> doesn't match (incorrect)
Run Code Online (Sandbox Code Playgroud)
在最后一种情况下,正则表达式的行为并不像我想要的那样.它应匹配"redtest",因为"redtest"不是("red","green"或"blue").
有关如何修复正则表达式的任何想法?
根据这篇文章:http://www.maltblue.com/tutorial/zend-framework-2-servicemanager
ServiceManager"简而言之就是一个提供对象的简单应用程序注册表".所以,我认为它应该是一个单例,我们可以在应用程序的任何地方访问.但是在ServiceManager的情况下,它不是.
为什么我不能在应用程序的任何位置获取服务定位器实例?
如果我对文本应用旋转,它将不会在Firefox和Chrome中呈现消除锯齿(仅在Windows中),但它在IE中正确呈现.此外,它在Mac OS X中的Chrome和Firefox中正确呈现.
以下是比较Windows 8中三个浏览器的屏幕截图:
上面的CSS转换很简单
transform: rotate(-1.5deg) translateY(-2px);
Run Code Online (Sandbox Code Playgroud)
这是一个小提琴:
有任何想法吗?
我需要编写一个视图助手来获取服务并使用它做一些事情.我成功实现了视图助手,可以访问服务定位器.问题是,当调用__invoke方法时,无法通过服务定位器找到我想要获取的服务.
视图助手代码:
<?php
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper,
Zend\ServiceManager\ServiceLocatorAwareInterface,
Application\Model;
class LoggedCustomer extends AbstractHelper implements ServiceLocatorAwareInterface
{
use \Zend\ServiceManager\ServiceLocatorAwareTrait;
public function __invoke()
{
$model = new Model\Customer($this->getServiceLocator());
return $model->getCurrent();
}
}
Run Code Online (Sandbox Code Playgroud)
模型代码的片段:
namespace Application\Model;
use Application\Entity,
Andreatta\Model\Base as Base;
class Customer extends Base
{
/**
*
* @return Zend\Authentication\AuthenticationService
*/
public function getAuthService()
{
$serviceLocator = $this->getServiceLocator();
return $serviceLocator->get('Application\Auth');
}
/**
*
* @return Zend\Authentication\Adapter\AdapterInterface
*/
protected function getAuthAdapter()
{
return $this->getAuthService()->getAdapter();
}
public function getCurrent()
{
$authService = $this->getAuthService();
if …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
#include <stdio.h>
#include <malloc.h>
void allocateMatrix(int **m, int l, int c)
{
int i;
m = (int**) malloc( sizeof(int*) * l );
for(i = 0; i < l; i++)
m[i] = (int*) malloc( sizeof(int) * c );
}
int main()
{
int **m;
int l = 10, c = 10;
allocateMatrix(m, l, c);
m[0][0] = 9;
printf("%d", m[0][0]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码将生成内存分配错误并将崩溃.
但下面的代码将正常工作,问题是:为什么?
#include <stdio.h>
#include <malloc.h>
int** allocateMatrix(int l, int c)
{
int i;
int **m = (int**) …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
void error_callback(int error, const char* description)
{
fputs(description, stderr);
}
int main( void )
{
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Open a window and create its OpenGL context
glfwSetErrorCallback(error_callback);
window = glfwCreateWindow( 1024, 768, "Tutorial 16 - Shadows", NULL, NULL);
if( window == NULL ){
//fprintf( stderr, "Failed to open GLFW window. If you have an …Run Code Online (Sandbox Code Playgroud) 我目前有这个算法:
char** mergeLists(char **a, char **b, int sizeA, int sizeB, int *lSize)
{
char **list = malloc( sizeof(char *) );
int pA = 0, pB = 0, listSize = 0;
while (pA != sizeA && pB != sizeB)
{
list = realloc(list, sizeof(char *) * (++listSize) );
if (strcmp(a[pA], b[pB]) < 0)
{
list[listSize-1] = a[pA];
pA++;
}
else
{
list[listSize-1] = b[pB];
pB++;
}
}
*lSize = listSize;
return list;
}
Run Code Online (Sandbox Code Playgroud)
但它似乎有一些错误.我目前正在运行此测试:
char *l1[6];
l1[0] = "a";
l1[1] = …Run Code Online (Sandbox Code Playgroud)