Jump to content

Recommended Posts

I'm stuck!

I need to know how to phrase an expression to get rid of a second span.

It goes something like this...

<span style='font-weight:bold;'><span style='font-weight:bold;'>some text</span></span>

Obviously I only need one span rather than two.

It goes

$description=preg_replace("what goes here???","",$description);

My head is melting!

This will cause problems if the spans are actually different, because it will remove the additional </span>. Will this occur in your data?

 

<pre>
<?php
$data = "<span style='font-weight:bold;'><span style='font-weight:bold;'>some text</span>";
echo htmlspecialchars(preg_replace('%(</?span[^>]*>)\1+%', '$1', $data));
?>
</pre>

All spans should be the same.  I replaced all spans with the ones above (or rather you did! thanks again) and then I replaced all <strong> tags with the same span tags.... thus the double occurance in places.  I'll put in the code you just gave me and see what transpires.

try

<?php
$text = "<span style='font-weight:bold;'>bla <span style='font-weight:bold;'>some text</span></span>";

echo preg_replace("/(?<=<span style='font-weight:bold;'>)(.*?)<span style='font-weight:bold;'>(.*?)<\/span>(?=<\/span>)/i",'\1\2',$text);
?>

Code starts

$query=mysql_query("SELECT * FROM mytable") or die (mysql_error());
while($result=mysql_fetch_array($query)){
$initialdescription=$result['description'];

then there is a bit more code with replaces etc thats all fine.

 

Then I used

 

$description=preg_replace('%(?span[^>]*>)\1+%','$1',$description);

Then I have

$description=mysql_real_escape($description);

 

Then

mysql_query("UPDATE mytable SET description='$description' WHERE description='$initialdescription'") or die(mysql_error());
}

It wont work. 

If I remove

WHERE description='$initialdescription'

then it runs but it updates all the descriptions to be the same... would have been a disaster if I hadn't backed it up.

If I leave it in I get a mysql error because it doesn't seem to like something caused by mysql_real_escape I presume.

I'm really in the dark here.... way out of my depth.

error is

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'text-align:center;'> Pharmacy Technician&nb' at line 5

I don't understand it. I'm told there is nothing wrong with the mysql syntax. Any ideas?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.