Search and replace for multiline html

Hello, I need to replace some html content on 200+ pages of a site and all these pages are built with Beaver Builder.

I am familiar and experienced with using Better Search and Replace and also Database Search and Replace Script in PHP | inter.connect for such as task.

I understand that the Beaver Builder content is stored in the postmeta table and is serialized.

The issue is that when I copy the content I need to find and replace directly from the database using phpMyAdmin and paste it directly into either of these tools the content is not found.

I have discovered through testing that this is due to white space and new lines in the html. If I search on content which is all shown on a single line in phpMyAdmin and does not have any white space then it is found.

However the content that I need to replace is correctly formatted html. It is shown in the database in php my admin like this?

<div class="wow">
   <a href="blah"><span>Some text</span></a>
</div>

So how can I do a search and replace for this multiline content in the Beaver Builder data?

How exactly do I search on space characters, tab characters and new line characters given there are no   and /n or similar characters showing when I view the Beaver Builder data in the database?

Thanks

You will most likely need a regular expression to find your HTML then you can search for tabs \t spaces \s etc.

BSR does not support regular expressions and thier latest version 1.4.4 is totally broken it does not work in serial data so you might want to give 1.4.3 a try first with your text.

Failing that you will have to use a regex and wp-cli search-replace which does support regex

You can use this site to test your regex skills https://regex101.com/

Thanks very much for your reply and suggestions.

I have tried to achieve what I need to do with Regex and it does not seem possible as the Better Search and Replace tool does not support Regex and when I try to use Regex in the Interconnect tool I get an Ajax error. Even for the most simple Regex search the error shows an error. Please note this is not a server config issue as I do not get the Ajax error if I search using the interconnect tool without using Regex. It seems to be an error exclusively when using Regex in that tool. There is no support for that tool so that is a dead end.

I have no shell access on the server to use CLI scripts.

So I have no functional way to search and replace using Regex.

There must be a better way. Why doesn’t Beaver Builder come with a search/replace function for it’s own data? Surely I’m not the only person who ever encoutered the need to search and replace on serialized html data created by Beaver Builder.

Why doesn’t Beaver Builder come with a search/replace function for it’s own data?

Its not Beaver Builders data. We use WP functions to save the array of options data to the post meta table, wordpress then serialises it.

Better search and replace has worked flawlessly for years to change urls in the serialised data ( except for version 1.4.4 which is broken ) but until now nobody has ever wanted to search and replace multiple lines of data. A quick google finds this plugin

Maybe give that a try,

Hi Pross,

Thanks very much for your response and the suggestion of an alternative search tool. The search regex tool works perfectly to find and replace content in serialized data using regex. Thanks :slight_smile:

However, despite supporting serialized data, when I do a find a and replace using this tool on Beaver Builder content with whitespace or line breaks the content is corrupted in some way and when viewing the page on the front end the Beaver builder content is no longer shown.

Even if all I run is this to remove the white space before the closing anchor tag it still corrupts the whole beaver builder content for that page.

Search: DOWNLOAD<br><b>SPECIFICATION</b>[\s\n]*</a>
Replace: DOWNLOAD<br><b>SPECIFICATION</b></a>

I notice if I try to edit the corrupted content in beaver builder that it has changed the whole field from HTML to text and ripped out all the html tags.

What am I missing here? How can I make changes to Beaver Builder content in the database without corrupting the whole page content?

Thanks,
Nicole

Sounds like that plugin is not serialising the data properly so because it is now broken wordpress can no longer read it, so BB resorts to just showing the wp content in a text module. Do you have an example of a broken page so I can confirm that?

Hi Pross,
Thanks for your assistance. It is not just this one plugin which causes the issue. Even if I make changes directly in phpMyAdmin (and obviously serialize the changes correctly) the Beaver Builder data still becomes corrupted. The BB data appears to be stored in a bunch of different places. The WP options table, the post itself and a few times in postmeta for the current and various history states. I have tried making the same changes in all these locations and still the data becomes corrupted.

As for an example of the broken page, this is what the HTML looks like before the change is made:

<div class="summary entry-summary">
		<h1 class="product_title entry-title">Flex</h1><p class="price"></p>
<div class="woocommerce-product-details__short-description">
	<p>Flex is a simple yet effective array of both linear and organic shapes that create an interesting modular seating arrangement. A low key aesthetic of the highest manufacturing quality.</p>
<p>In house fabrics and COM available for this collection</p>
</div>
<div class="product_meta">

	
	
	<span class="posted_in">Categories: <a href="https://www.innova-group.com.au/product-category/cafe-furniture/" rel="tag">Cafe Furniture</a>, <a href="https://www.innova-group.com.au/product-category/ottomans/" rel="tag">Ottomans</a>, <a href="https://www.innova-group.com.au/product-category/restaurant/" rel="tag">Restaurant</a></span>
	
	
</div><div class="woocommerce-specification"><div class="woocommerce-tabs wc-tabs-wrapper">
		<ul class="tabs wc-tabs" role="tablist">
							<li class="description_tab active" id="tab-title-description" role="tab" aria-controls="tab-description">
					<a href="#tab-description">Description</a>
				</li>
					</ul>
					<div class="woocommerce-Tabs-panel woocommerce-Tabs-panel--description panel entry-content wc-tab" id="tab-description" role="tabpanel" aria-labelledby="tab-title-description" style="">
				

<div class="fl-builder-content fl-builder-content-498 fl-builder-content-primary" data-post-id="498"><div class="fl-row fl-row-fixed-width fl-row-bg-none fl-node-5abc3f1735e33 fl-row-default-height fl-row-align-center" data-node="5abc3f1735e33">
	<div class="fl-row-content-wrap">
								<div class="fl-row-content fl-row-fixed-width fl-node-content">
		
<div class="fl-col-group fl-node-5abc3f1b170c1" data-node="5abc3f1b170c1">
			<div class="fl-col fl-node-5abc3f1b172ea" data-node="5abc3f1b172ea">
	<div class="fl-col-content fl-node-content"><div class="fl-module fl-module-html fl-node-5abc3f295464c" data-node="5abc3f295464c">
	<div class="fl-module-content fl-node-content">
		<div class="fl-html">
	<ul class="accordion">
    <li>
        <a class="spec" style="text-align: center;" href="/wp-content/uploads/2019/06/Flex.pdf" download="" target="_blank">
            DOWNLOAD<br><b>SPECIFICATION</b>
        </a>  

        <div class="content">
            <div class="drop-down">
                <div class="option">
                    <span>Options</span>
                   Linear and organic shapes available to form various modular settings 
In house fabrics and COM available for this collection 
                </div>
                <div class="warranty">
                    <span>Warranty</span>
                    5 year commercial warranty 
                </div>
                <div class="designer">
                    <span>Designer</span>
                     B&amp;T design team 
                </div> 
            </div>
        </div>
        
        <a class="toggle" href="#one">
            <div class="border">
                <svg class="svg-inline--fa fa-chevron-down fa-w-14" aria-hidden="true" data-prefix="fa" data-icon="chevron-down" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"></path></svg><!-- <i class="fa fa-chevron-down" aria-hidden="true"></i> -->
                <svg class="svg-inline--fa fa-chevron-up fa-w-14" aria-hidden="true" data-prefix="fa" data-icon="chevron-up" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M240.971 130.524l194.343 194.343c9.373 9.373 9.373 24.569 0 33.941l-22.667 22.667c-9.357 9.357-24.522 9.375-33.901.04L224 227.495 69.255 381.516c-9.379 9.335-24.544 9.317-33.901-.04l-22.667-22.667c-9.373-9.373-9.373-24.569 0-33.941L207.03 130.525c9.372-9.373 24.568-9.373 33.941-.001z"></path></svg><!-- <i class="fa fa-chevron-up" aria-hidden="true"></i> -->
            </div>
        </a>
    </li>
</ul></div>
	</div>
</div>
</div>
</div>
	</div>
		</div>
	</div>
</div>
</div><div class="uabb-js-breakpoint" style="display: none;"></div>			</div>
			</div></div>

	</div>

and this is what it looks like after the change is made:

<div class="summary entry-summary" bis_skin_checked="1">
		<h1 class="product_title entry-title">Flex</h1><p class="price"></p>
<div class="woocommerce-product-details__short-description" bis_skin_checked="1">
	<p>Flex is a simple yet effective array of both linear and organic shapes that create an interesting modular seating arrangement. A low key aesthetic of the highest manufacturing quality.</p>
<p>In house fabrics and COM available for this collection</p>
</div>
<div class="product_meta" bis_skin_checked="1">

	
	
	<span class="posted_in">Categories: <a href="https://www.innova-group.com.au/product-category/cafe-furniture/" rel="tag">Cafe Furniture</a>, <a href="https://www.innova-group.com.au/product-category/ottomans/" rel="tag">Ottomans</a>, <a href="https://www.innova-group.com.au/product-category/restaurant/" rel="tag">Restaurant</a></span>
	
	
</div><div class="woocommerce-specification" bis_skin_checked="1"><div class="woocommerce-tabs wc-tabs-wrapper" bis_skin_checked="1">
		<ul class="tabs wc-tabs" role="tablist">
							<li class="description_tab active" id="tab-title-description" role="tab" aria-controls="tab-description">
					<a href="#tab-description">Description</a>
				</li>
					</ul>
					<div class="woocommerce-Tabs-panel woocommerce-Tabs-panel--description panel entry-content wc-tab" id="tab-description" role="tabpanel" aria-labelledby="tab-title-description" style="" bis_skin_checked="1">
				

<div class="fl-builder-content fl-builder-content-498 fl-builder-content-primary" data-post-id="498" bis_skin_checked="1"></div><div class="uabb-js-breakpoint" style="display: none;" bis_skin_checked="1"></div>			</div>
			</div></div>

	</div>

I have compared the two side by side and it just ripped everything out of the fl-builder-content div.

As I mentioned above this is not only related to the Search Regex plugin. If I log into phpmyadmin directly and find the entry in postmeta for that post ID with the meta key _fl_builder_data and I open to edit it the data becomes corrupted after I save it again even if all I change is one letter from upper case to lower case! That would not affect the serialization at all. Even if I then change it back again to exactly how it was before the data remains corrupted. Just editing and saving with phpMyAdmin corrupts the data for Beaver Builder. The only way to fix this is to restore a database backup as simply reverting the change I made will not fix it.

It really seems like it is virtually impossible to edit content created in Beaver Builder without editing it in Beaver builder itself… which isn’t ideal when you have to edit hundreds of pages.

Do you have any further suggestions?

Thanks very much,

Nicole

How are you reserialising it?