草庐IT

custom-tags

全部标签

php - 使用 get_meta_tags() 和 get_headers() 进行异常处理?

在PHP中,我使用get_meta_tags()和get_headers(),但是,当出现404时,这两个函数会抛出警告。我有什么办法可以捕获它吗?谢谢! 最佳答案 get_headers不会在404上抛出警告/错误,但get_meta_tags会。所以你可以检查标题响应并在它不正常时做一些事情:$url='http://www.example.com/';$headers=array();$metatags=array();$validhost=filter_var(gethostbyname(parse_url($url,PHP

php - 如何用数组 [INDEX] 元素替换 {tag_INDEX}

我有这样的字符串;"String{tag_0}text{tag_2}and{tag_1}"现在我需要用数组中的元素替换所有{tag_INDEX}$myArray=array('a','b','c');所以替换后它应该是这样的:"Stringatextcandb"最好的方法是什么?我正在尝试使用preg_replace和preg_replace_callback但没有任何好的结果 最佳答案 $newStr=preg_replace('/{tag_(\d+)}/e','$myArray[\1]',$str);

PHP 正则表达式不起作用 - 解析 {{tags}}

我想做的是它解析以下字符串的方式是{{}}中的所有占位符都被替换为“默认”指示的值。例如,{{time,default=noon}}应该变成noon。这是我试过的代码:$input='Itwasa{{color,default=black}}andscary{{phase}}.Asthe{{animals,default=dogs}}{{make_sound,default=barked}}andthetreesswayed{{setting,default=tothebreeze}},a{{size,default=}}{{monster,default=troll}}thateme

php - child 主题模板-tags.php

我使用的主题有一个inc/template-tags.php文件需要用子模板-tags.php覆盖将文件添加到我的基于inc/文件夹和根子主题文件夹的子主题文件夹似乎不会覆盖父文件。添加include(get_stylesheet_directory().'/inc/template-tags.php');我的childfunctions.php导致WordPress白屏死机。有人知道怎么做吗? 最佳答案 答案是在子functions.php中使用以下内容if(!function_exists(twentyfourteen_post

php - WooCommerce 法典 : how to set the user/customer on an order

我正在编写一个负责付款和交付的WooCommerce插件。现在我正在根据当前购物车创建订单。一切正常,元素和费用正确,唯一的问题是订单显示为“访客”,而不是当前登录的用户(即使正确的电子邮件地址该用户在订单上)。这是我的代码:$cart=WC()->cart;$checkout=WC()->checkout();$order_id=$checkout->create_order();$order=wc_get_order($order_id);$order->user_id=apply_filters('woocommerce_checkout_customer_id',get_cur

Php smarty strip_tag 允许特定标签

有没有办法像默认情况下一样在phpsmarty中使用strip_tags以允许特定的html标签通过?stip_tags($a.message,'');smarty中的等价物是什么?{$a.message|strip_tags} 最佳答案 我正在使用Smarty2.6.26和strip_tags使用指定要保留哪些标签的参数。试试这个:PHP:$string="notboldiframegoesawayparagrapheddivkept.";$smarty->assign('string',$string);在模板中:{$strin

php - 使用 Advanced Custom Fields 和 Contact Form 7 显示表单

我希望我的用户能够输入ContactForm7简码到Wordpress编辑器中的自定义字段。我使用ACF创建了自定义字段我可以将该值拉到页面上,但是当我尝试将它包含在短代码中时,它会返回404。这段代码:返回:[contact-form-7404"NotFound"]如果我用这样的值创建一个变量:echo返回:[contact-form-7id="473"title="LearnMoreForm"]但是在将该值放入echodo_shortcode函数列表后,我得到了相同的404:我错过了什么? 最佳答案 TodoitWithACFp

php - WordPress Admin : When placing a Custom Post Type as a submenu of a parent menu, 父菜单链接被 CPT 覆盖

我注册了一个自定义帖子类型,我不希望它有自己的菜单,而是想将它作为一个名为my-custom-parent-page.这是我的代码:register_post_type('my_custom_post_type',array('labels'=>array('name'=>__('Books','mcpt'),'singular_name'=>__('Book','mcpt'),),'supports'=>array('title','editor'),'show_ui'=>true,'show_in_nav_menus'=>false,'show_in_menu'=>'my-cust

具有特定 ID 的 div 的 PHP Strip_tags?

有谁知道修改后的strip_tags函数是否存在,您可以在其中指定要剥离的标签的ID,并且可能还指定删除标签中的所有数据。举个例子:blablablaRunning:new_strip_tags($data,'two',true);必须返回:那里有这样的东西吗? 最佳答案 您可以使用DOMDocument和DOMXPath为此。...blablabla';$doc=newDOMDocument;$doc->preserveWhiteSpace=false;$doc->loadhtml($html);$xpath=newDOMXPat

php - FOSUserBundle 和 REST Api 调用 : How to use custom FormType?

我在我的Symfony2网站上使用FOSUserBundle。现在我正在开发一个API以允许通过RESTAPI调用进行注册。我已经覆盖了FOSUserBundle的RegistrationController:ApiRegistrationController.php:/***@Route("/user/",defaults={"_format"="json"},requirements={"_method"="POST"})**/publicfunctionregisterAction(Request$request){[...]$form=$formFactory->createF