Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'preg_match'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 3 results

  1. I'm having a little trouble with preg_replace. The aim is to take a shortcode and replace it with some html code. The shortcode is of the format [image file=name.ext]. Each instance of the shortcode in some content should be replaced with <img src="path/to/images/name.ext" alt="name image" /> What is actually happening is the shortcode is being replaced with [<img src="path/to/images/name.ext" alt="name image" />] Printing out the relevant array shows no brackets so not sure where to look to solve this. Also can preg_match be used to find more than one occurrence of a pattern? The php manual indicates yes, but my testing was only coming up with one occurrence so I've resorted to using preg_match_all. Here's my test file with some content if you want to test it out. As ever please suggest any improvements. Thanks. define ('BASE_URL', '/path/to/root/'); $content = '<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> [image file=file1.jpg]<h3>Ipsem</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> [image file=file2.jpg]<h3>Lorem</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. </span>ipsem lorem blah di blah.</span>'; $html_content=replace_shortcodes($content); echo( $html_content); function replace_shortcodes($content){ $html_array=array(); $shortcodes = get_all_shortcodes($content); foreach ($shortcodes as $shortcode) { $filename = get_sc_attr($shortcode); $alt = substr($filename, 0, strpos($filename,'.')); $html_array[]='<img src="' . BASE_URL . 'images/' . $filename . '" alt="'. $alt. ' image" />'; } $html_content= preg_replace($shortcodes, $html_array, $content); return $html_content; } function get_all_shortcodes($content){ $sc_regex = '/\[\s*image\s+file\s*=\s*[\w-]+\.[\w-]+\s*\]/'; preg_match_all($sc_regex, $content, $matches); return $matches[0]; } function get_sc_attr($shortcode) { $length = (strpos($shortcode,']') - strpos($shortcode,'=')); $filename = trim(substr($shortcode, strpos($shortcode,'=') +1,$length-1)); return $filename; }
  2. I've been using a script to check submissions for proper email formatting. It looks like this: eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) Note, that I didn't write this script, it was provided by someone else. It's worked fine for years, but now I'm getting an error message saying the function has been deprecated. I think my host must have installed a new version of PHP, 5.3.2. That's cool, I just need to figure out what to replace this code with. I've done a little research and it seems there are several ways to approach this, including: 1. just replace "eregi" with "preg_match." 2. use "filter_var" and "FILTER_VALIDATE_EMAIL" instead. Any advice as to what would be the best way to update this script would be greatly appreciated. Thanks!
  3. Can you please tell me how to change this preg_match, which is trying to stop the html anchors. I think this has been working up until recently. Someone is placing links within the email. I also include one of the email that got through. Is it because the <a is on one line and the html is on the next line? my code: // check for html links and not permitted if (preg_match('/<a\s/', $scrubbed['comments'])) { echo '<p style="font-weight: bold; color: #C00">Not Permitted.</p>'; } else { // no html anchor the email: <p>hi!<br>for a while I wasnt feeling like myself this caught my eye right away its crazy how the tables have turned check out what I mean<br><a href="http://ansel.pl/GaryBailey15.html">http://ansel.pl/GaryBailey15.html</a><br>see you later</p>
×
×
  • Create New...