Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 978425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:03:22+00:00 2026-05-16T04:03:22+00:00

OK, I need to scan many HTML / XHTML documents to see if a

  • 0

OK, I need to scan many HTML / XHTML documents to see if a particular file has been embedded with SWFObject. If it’s the case, I need to replace the call to something else.

So far I have extracted the <script> contents where the calls can be made. Now I need to scan this string to check if the call is there and if it’s there I need to replace it.

I know this is a bit odd, but the content comes from a third party which we don’t have control on.

Since the call can be made in many different syntax, I will need a regular expression to find and replace the calls.

OK imagine the following scenario:

I’m searching if the file test.swf is embedded with SWFObject in the file.

The <script> content look like this:

alert('test.swf');
//some other random stuff here
swfobject.embedSWF("test.swf",
"The alternative content can screw the regexp with );", "300", "120",
"9.0.0", false, flashvars, params, attributes);

Now I would like to replace swfobject.embedSWF (and all parameters) to something else.

Is there a not too horrible way to do this? Don’t forget that the call can be on one or many lines, that the parameters can be wrapped with single quotes (‘) or double quotes (“), that whitespace can be all around…

EDIT: OK since catching all kind of JS syntax is a bit overkill I will simplify the requirement:

The regular expression can assume only the following

  1. The call is always on the same line
  2. It always start with swfobject.embedSWF (case sensitive)
  3. Is then followed (or not) by whitespaces and then a (
  4. Is then followed (or not) by whitespaces and then a " or a ' (either one but one of the 2 is required)
  5. Is then followed by the filename
  6. Is then followed by " or ' (if we can ensure that it’s the same char that in 4 good if not too bad)
  7. Is then followed (or not) by whitespaces and then a ,
  8. Is then followed by anything
  9. Is then followed by ) then any whitespaces (or not) then ; then an end of line.

It should be much simpler to parse this way (I guess).

EDIT 2: I’ve cooked a solution. I think I’m close but it’s not working, Anyone can help? 0 should match but it’s not…

<?php

$myFilename = 'test.swf';
$testCases = array();
$testCases[] = 'swfobject.embedSWF("test.swf", "The alternative content can screw the regexp with );", "300", "120", "9.0.0", false, flashvars, params, attributes);';

foreach ($testCases as $i => $currTest)
{
    $currResult = preg_match('/\s*swfobject\.embedSWF\s*\(\s*(["\'])(' . preg_quote($myFilename)  . ')[^"\']+\1\s*,[\s\S]+?\)\s*;\s*$/', $currTest);
    if ($currResult === false || $currResult < 1)
        echo $i, ' Not matching', PHP_EOL;
    else
        echo $i, ' Matching', PHP_EOL;
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:03:22+00:00Added an answer on May 16, 2026 at 4:03 am

    In regards of your EDIT2…

    I’m not the best with regular expressions but you can try:

    $currResult = preg_match('/\s*swfobject\.embedSWF\s*\(\s*(["\'])(' . preg_quote($myFilename)  . ')\1\s*,[\s\S]+?\)\s*;\s*$/', $currTest);
    

    Seems to work OK for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to scan an input file and search for a specific value. How
I am developing a C# .NET 2.0 application wherein I need to scan for
I need an algorithm that introduces data like a stack, so when I scan
I've been struggling all day with trying to find classes that converts/decodes ASCII characters
I am in need of a data storage type and algorithm for keeping track
I need to store set value in MySQL column. I completely like the build-in
I'm creating a program where I need to search an FTP server and download
I wish to generate a QR image so people can scan to visit my
hi dear friends and good morning The following question may be complicated and critical
this is my first question here; hope I'll be clear enough... I've got this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.