0
我正在做一个前端表单,让用户提交一个有效但也是图片的网址,以.jpg,.png或.gif。检查是否有效的URL以.jpg,.png或.gif结尾于wordpress文章内容
这是我的形式:
<form action="" id="primaryPostForm" method="POST">
<fieldset>
<p>Accepting GIF/JPG/PNG URL (Max size: 3MB)</p>
<label for="postTitle"><?php _e('* POST TITLE:', 'framework') ?></label>
<input type="text" name="postTitle" id="postTitle" class="required" value="<?php if (isset($_POST['postTitle'])) echo $_POST['postTitle']; ?>" />
</fieldset>
<fieldset>
<label for="postContent"><?php _e('* URL:', 'framework') ?></label>
<textarea name="postContent" id="postContent" class="required" <?php if (isset($_POST['postContent'])) { if (function_exists('stripslashes')) { echo stripslashes($_POST['postContent']); } else { echo $_POST['postContent']; } } ?>></textarea>
</fieldset>
<fieldset>
<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit"><?php _e('SUBMIT', 'framework') ?></button>
</fieldset>
</form>
这是我得到的信息并创建的帖子:
if (isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
$post_information = array(
'post_title' => wp_strip_all_tags($_POST['postTitle']),
'post_content' => $_POST['postContent'],
'post_type' => 'post',
'post_status' => 'publish'
);
$new_post = wp_insert_post($post_information);
我想检查是否插在POST_CONTENT字符匹配的URL以.jpg/png/gif结尾,并从这一点创建一个像这样的条件标签:
if $ _POST ['postContent'] == URL以JPG/PNG/GIF结尾{ do somet hing}
我该如何做到这一点?
你有什么试过?有很多例子来验证URL(正则表达式),并且比较字符串结尾非常简单。 –